WP7 后台音频资源不再可用 [英] WP7 background audio resources are no longer available
问题描述
我正在将 BackgroundAudioPlayer
用于我的 Windows Phone 7 音乐&视频应用.播放一些音乐后,我使用 MediaPlayerLauncher
播放视频,然后按 Back 返回到我的应用程序.每当我使用 BackgroundAudioPlayer.Instance
时就在那里.我收到错误背景音频资源不再可用".
I'm using BackgroundAudioPlayer
for my Windows Phone 7 music & video application. After I play some music, I play video using MediaPlayerLauncher
, then press Back to return to my app. There whenever I use BackgroundAudioPlayer.Instance
. I receive error "The background audio resources are no longer available".
MSDN 上的某人 建议使用 try/catch,但这不是一个好主意,并且会减慢应用程序的速度.
Someone on MSDN suggests using try/catch, but this is not a good idea, and can slow down the app.
其他建议在启动 MediaPlayer
之前调用 BackgroundAudioPlayer.Instance.Close()
.但是,当我播放音乐时,代理再次加载.dll,这需要很长时间.
Other suggests call BackgroundAudioPlayer.Instance.Close()
before launch MediaPlayer
. However, when I play music, the agent load .dll again, which takes very much time.
如何解决这个问题?
推荐答案
如果您在播放完音频后播放视频,操作系统肯定会终止"您的后台音频播放器.从您的问题来看,这似乎是 100% 可重现的,这将证实这一点.您唯一的选择是在您调用 BackgroundAudioPlayer.Instance.Close()
后再次重新启动后台音频播放器,然后播放您的视频.正如您所说,当您启动 BAP 时,需要重新加载您的播放器 DLL.
If you play a video after your audio the OS will definitely "terminate" your Background Audio Player. From your question it seems this is reproducible 100% of the time which would confirm this. Your only option is to restart the background audio player again after you have called BackgroundAudioPlayer.Instance.Close()
, and then played your video. Which as you said will require reloading your player DLL when you start the BAP.
根据评论更新跟进
如果您没有实现流式音频代理,而只是实现了 AudioPlayer 代理,那么无论如何您都无法杀死进程.操作系统在需要让您处理操作(例如:用户操作、跟踪结束、关闭)时启动进程.
If you aren't implementing a streaming audio agent but only an AudioPlayer agent there isn't a process for you to kill anyway. The OS spins up a process as and when it needs to get you to process an action (e.g.: user action, track ended, shutdown).
BackgroundAudioPlayer.Instance.Close()
只是确保操作系统在 OP 等场景中干净地释放这些资源.
BackgroundAudioPlayer.Instance.Close()
just makes sure that the OS releases those resources cleanly in a scenario such as the OP has.
要重新启动背景音频,只需再次调用BackgroundAudioPlayer.Instance.Play()
.
To restart background audio, just call BackgroundAudioPlayer.Instance.Play()
again.
这篇关于WP7 后台音频资源不再可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!