How to access albums, artists, playlists in Windows Phone Runtime?

Earlier access to Albums, Genresetc. could be used withMediaLibrary

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

But it is not available in Windows Runtime applications. What is an alternative way to access this data?

This application is for Windows Phone Runtime.

+4
source share
1 answer

Use this

var folder = Windows.Storage.KnownFolders.MusicLibrary;
var files = await folder.GetFilesAsync();

Use StorageItemContentProperties in the StorageFile and call GetMusicPropertiesAsync it returns 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);
}
+2
source

Source: https://habr.com/ru/post/1545548/


All Articles