如何在Windows Phone Runtime中访问相册,艺术家和播放列表?

时间:2014-06-22 12:33:16

标签: c# windows-phone-8 windows-runtime windows-phone windows-phone-8.1

以前可以使用Albums

访问GenresMediaLibrary
using(MediaLibrary library = new MediaLibrary())
{
    SongCollection songs = library.Songs;
    Song song = songs[0];
    MediaPlayer.Play(song);
}

但它在Windows运行时应用程序中不可用。访问这些数据的另一种方法是什么?

这是一款Windows Phone Runtime应用程序。

1 个答案:

答案 0 :(得分:2)

使用此

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);
}