问题
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".
Someone on MSDN suggests using try/catch, but this is not a good idea, and can slow down the app.
Other suggests call BackgroundAudioPlayer.Instance.Close()
before launch MediaPlayer
. However, when I play music, the agent load .dll again, which takes very much time.
How to fix this ?
回答1:
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.
Update following up from comments
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()
just makes sure that the OS releases those resources cleanly in a scenario such as the OP has.
To restart background audio, just call BackgroundAudioPlayer.Instance.Play()
again.
来源:https://stackoverflow.com/questions/13641735/wp7-background-audio-resources-are-no-longer-available