我正在开发一个Windows 10通用音乐应用程序,我想将我的Windows Phone 8.1 silverlight应用程序转换为Windows 10.如何在Windows 10应用程序中获取库中所有歌曲的列表? 在Windows Phone 8.1中,我做过类似的事情:
SongCollection collection;
MediaLibrary library = new MediaLibrary();
collection = library.Songs;
上面的代码不适用于Windows 10 sdk。有什么建议吗?
答案 0 :(得分:0)
Above code works only in windows phone *.
SongCollection collection;
MediaLibrary library = new MediaLibrary();
collection = library.Songs;
For windows phone 8.1 and Windows 10 you should use following code
var songs = (await KnownFolders.MusicLibrary.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName)).ToList();
var albums = (await KnownFolders.MusicLibrary.GetFoldersAsync(CommonFolderQuery.GroupByAlbum)).ToList();
The above to work you should add following capability in Package.appxmanifest file.
<Capabilities>
<uap:Capability Name="musicLibrary" />
</Capabilities>