예제 #1
0
        private async Task <bool> GetMediaFiles()
        {
            var fileList = await KnownFolders.MusicLibrary.GetFilesAsync();

            foreach (var file in fileList.Where(x => x.ContentType.Contains("audio")))
            {
                // Add to collection for displaying list of media file sources
                MediaFileCollection.Add(file);

                // Add source to the media player's playlist
                var source = MediaSource.CreateFromStream(await file.OpenAsync(Windows.Storage.FileAccessMode.Read), file.ContentType);
                MusicPlayerController.AddToPlaylist(source);
            }
            return(true);
        }
        private async Task <bool> GetMediaFiles()
        {
            var query        = CommonFileQuery.DefaultQuery;
            var queryOptions = new QueryOptions(query, new[] { ".mp3", ".wav" })
            {
                FolderDepth = FolderDepth.Shallow
            };
            var queryResult = KnownFolders.MusicLibrary.CreateFileQueryWithOptions(queryOptions);
            var fileList    = await queryResult.GetFilesAsync();

            foreach (var file in fileList)
            {
                // Add to collection for displaying list of media file sources
                MediaFileCollection.Add(file);

                // Add source to the media player's playlist
                var source = MediaSource.CreateFromStream(await file.OpenAsync(Windows.Storage.FileAccessMode.Read), file.ContentType);
                MusicPlayerController.AddToPlaylist(source);
            }
            return(true);
        }