Reputation: 190
I have a universal Windows store project. In Windows Phone
part, I use a BackgroundMediaPlayer.Current
to play audio. The app getting access to media files through KnownFolders.MusicLibrary
.
The problem is when I run my app on emulator with virtual SD Card, music plays and all goes nice. But when I deploy the app to my Lumia 920
running WP8.1 DevPreview
, and press 'Play' button, then nothing happens. No exceptions, no force-close... Completely nothing.
Question: Is this an internal storage issue (Lumia 920
have no SD Card) or BackgroundMediaPlayer
have a bug or bug is hiding in OS preview version?
Upvotes: 0
Views: 720
Reputation: 11
I just had the same problem.
If you register to the handler: mediaPlayer.MediaFailed += mediaPlayer_MediaFailed;
you will find out that you get an UnauthorizedAccessException
when playing local songs (not on SD card).
Here is what i did and how i solved it:
The error occurs due to BackgroundMediaPlayer.Current.SetUriSource
, which for whatever reason only works for files on SD cards.
So instead of passing the path of the file to SetUriSource
, I loaded the StorageFile
with
StorageFile sf = await StorageFile.GetFileFromPathAsync(musicDataFullPath);
and then
mediaPlayer.SetStreamSource((await sf.OpenStreamForReadAsync()).AsRandomAccessStream());
and so now it works....
Upvotes: 1