WP7 background audio resources are no longer available

I use BackgroundAudioPlayer for my Windows Phone 7 music and video application. After playing the music, I play the video using MediaPlayerLauncher , then click โ€œBackโ€ to return to my application. Where I use BackgroundAudioPlayer.Instance . I get the error " Background audio resources are no longer available .

Someone from MSDN suggests using try / catch, but this is not a good idea and may slow down the application.

Another suggests calling BackgroundAudioPlayer.Instance.Close() before starting MediaPlayer . However, when I play music, the agent downloads the .dll again, which takes a very long time.

How to fix it?

+1
source share
1 answer

If you play a video after your sound, the OS will definitely โ€œstopโ€ your background audio player. From your question, it seems that this is reproducible in 100% of cases, which will confirm this. Your only option is to restart the background audio player again after you call BackgroundAudioPlayer.Instance.Close() and then play your video. Which, as you said, will require reloading your playerโ€™s DLL when starting BAP.

Update after comments

If you do not implement an audio streaming agent, but only an AudioPlayer agent, you are not going to kill anyway. The OS starts the process as necessary to force you to process the action (for example: user action, end of track, shutdown).

BackgroundAudioPlayer.Instance.Close() simply ensures that the OS frees up these resources for free in a script such as OP.

To restart the background sound, just call BackgroundAudioPlayer.Instance.Play() again.

+2
source

Source: https://habr.com/ru/post/971211/


All Articles