Error when Play file .mp3 (StorageFile ) with Back

2019-09-17 14:43发布

问题:

I use Windows Phone 8.1 Runtime I get my song in isolated storage

My code : storageFile is song in isolated storage

IRandomAccessStream stream = await storagefile.OpenAsync(FileAccessMode.Read);
BackgroundMediaPlayer.Current.SetStreamSource(stream);
BackgroundMediaPlayer.Current.Play();

When I play it,but it not work , like photo (try emulator and device lumina 520)

http://photoshare7.com/image/f5a

_message: Unable to cast object of type 'Windows.Media.Playback.MediaPlayer ' to type 'Windows.Media.Playback.IMediaPlayerSource'

Please Help me .Tks all.Sr my English.

回答1:

I just ran into the same issue :) This happens when you call SetStreamSource from foreground application. See [https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn642090.aspx]. To play audio from a file, you need to send background audio player a message (see [How to pass an object to background project in Windows Phone?).