在隔离存储窗口中使用BackgroundMediaPlayer播放文件.mp3(StorageFile)时出现错误电话8.1 rt

时间:2015-02-06 07:40:52

标签: windows-runtime windows-phone windows-phone-8.1

我使用Windows Phone 8.1 Runtime 我把歌曲放在隔离的存储空间

我的代码: storageFile是隔离存储中的歌曲

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

当我播放它时,它不起作用,如照片(尝试模拟器和设备腔520)

http://photoshare7.com/image/f5a

_message: 无法将“Windows.Media.Playback.MediaPlayer”类型的对象强制转换为“Windows.Media.Playback.IMediaPlayerSource”

请帮助我。打电话给我。我的英语。

1 个答案:

答案 0 :(得分:1)

我刚遇到同样的问题:)当您从前台应用程序调用{​​{1}}时会发生这种情况。见[https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn642090.aspx]。要播放文件中的音频,您需要向背景音频播放器发送消息(请参阅[How to pass an object to background project in Windows Phone?)。