Search code examples
windows-phone-8windows-phone-8.1audio-playerbackground-music

Playing songs from a user's music library in WP8.1?


In WP8 I had to get the list of songs from "MusicLibrary" class and play it through the "MediaPlayer" class. It was simple enough. But both of these are gone in 8.1. Actually pretty much everything is gone. Even simple things like page navigation syntax has changed completely (and I don't see any logical reason behind doing that)

Can someone tell me how I can get the list of songs in the user's phone in WP8.1? And how to play them in the background? I can't find any documentation on 8.1 on the net at the moment. After a lot of googling I only managed to find one example which showed how to play a file from isolated storage. Please help..


Solution

  • I think you are targeting windows phone 8.1 (Windows Run time version) If you target windows phone 8.1 Silverlight almost everything is same as windows phone 8. Windows phone 8.1 winRt is targeted for code re-usability on window phone and windows store app. So if you are targeting both platforms then try to Use Universal Apps.

    Edit For Player use <MediaElement... and for accessing Music library use below code.

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

    Hope this helps.