以前可以使用Albums
访问Genres
,MediaLibrary
等
using(MediaLibrary library = new MediaLibrary())
{
SongCollection songs = library.Songs;
Song song = songs[0];
MediaPlayer.Play(song);
}
但是在Windows运行时应用程序中不可用。访问这些数据的替代方法是什么?
这是Windows Phone运行时应用程序。
最佳答案
用这个
var folder = Windows.Storage.KnownFolders.MusicLibrary;
var files = await folder.GetFilesAsync();
在StorageFile上使用StorageItemContentProperties并调用GetMusicPropertiesAsync会返回MusicProperties。
StorageFolder musicFolder = KnownFolders.MusicLibrary;
IReadOnlyList<StorageFile> fileList = await musicFolder.GetFilesAsync();
foreach (var file in fileList)
{
MusicProperties musicProperties = await file.Properties.GetMusicPropertiesAsync();
Debug.WriteLine("Album: " + musicProperties.Album);
Debug.WriteLine("Rating: " + musicProperties.Rating);
Debug.WriteLine("Producers: " + musicProperties.Publisher);
}