3
votes

around a week ago, I submitted an online Background Radio Streaming app for the Windows Phone store. The app was quite good (as I used the Emulator to test it, it was good on all the possible sectors) but when I submitted it for certification, it failed.

According the the error log, if someone is already playing a Music from Music + Video hub and then tries to open this app, both of the apps Crash and stop unexpectedly.

So far I understood, it is because the Music of Music + Video hub is also Background Music and for playing 2 Background Musics at the same time, the apps are Crashing. It can be some other reason but the described one seemed more logical to me.

So, is there anyone who can tell me how to change the state of the app of Music + Video hub? I want to pause or stop the app of Music + Video hub for the time being so that both of the states of the app are not same. In that way, the apps won't clash with each other in the background.

Can anyone help me in this regard?

1

1 Answers

5
votes

Use gameHasControl to check for other BAP using music:

bool gameHasControl = Microsoft.Xna.Framework.Media.MediaPlayer.GameHasControl;
if (!gameHasControl)
{
   MessageBox.Show("stopping other player"); // normally you should ask if to do that      
   BackgroundAudioPlayer.Instance.Stop();
}

Once it is Stopped, when you start your BAP, then old instance invokes Shutdown(), and your BAP will be new Instance, which you can normally use. The same is when your BAP is in memory and you start to play from Music+Video Hub.

Only watch out, because when you use XNA, you sometimes need to do:

FrameworkDispatcher.Update();

Otherwise your App will sometimes crash. Good luck.

EDIT - after comment

To make it work you need to add a reference to Microsoft.Phone.BackgroundAudio or use like this:

Microsoft.Phone.BackgroundAudio.BackgroundAudioPlayer.Instance.Stop();

BackgroundAudioPlayer is a Singleton which you are allowed to use - in this case - Stop it playing (of course give the choice to the User).