以前可以使用MediaLibrary访问专辑,流派等
using(MediaLibrary library = new MediaLibrary())
{
SongCollection songs = library.Songs;
Song song = songs[0];
MediaPlayer.Play(song);
}
但它在Windows运行时应用程序中不可用.访问这些数据的另一种方法是什么?
这是一个Windows Phone Runtime应用程序.
最佳答案 用这个
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);
}