joe
joe

Reputation: 17478

Windows Phone leave background music playing

My Windows Phone app was rejected because when I play a sound in the browser in my app it stops existing background music from playing (rejection issue 6.5.1).

How do I update my application to not stop background music?

My JavaScript is something like this:

var mySound = new Audio(soundpath);

Sound.play(mySound);

I could not find anything in Microsoft.Xna.Framework.Media that handles how the app handles browser sound, but maybe I missed something?

Upvotes: 0

Views: 2081

Answers (2)

Luke Dickinson
Luke Dickinson

Reputation: 11

What you are looking for is from the xna soundeffect

Here is what I use and it works for me great for all my sound effects. (You cannot use music with a 'soundeffect' object, as it will not pass the windows store qualifications. You have to use the MediaElement for music) I can’t remember which you need but I have all these includes

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;

and this function

private static void LoadSoundEffect(string fileName, SoundEffectInstance mySound)
{
    var stream = TitleContainer.OpenStream("Sounds/" + fileName);
    var effect = SoundEffect.FromStream(stream);
    FrameworkDispatcher.Update();
    mySound = effect.CreateInstance();   
}

If you use a SoundEffectInstance, you can start,pause,stop the soundeffect etc. without all the problems.

SoundEffect works as well, but I prefer the SoundEffectInstance.

Edit: If you use soundeffect, it will not effect the music being played.

Upvotes: 1

Jeremiah Isaacson
Jeremiah Isaacson

Reputation: 340

I'm assuming that you are building a native Windows Phone app (.XAP) and then using a browser control to display your app content. If that is the case, you have checks that you will need to perform when the app is first opened. Below is a description of how to resolve that issue.

You will need to add this piece of code to your app (I suggest you check this every time your app loads/opens). Add a reference with the using statement as well for the Media.

if (Microsoft.Xna.Framework.Media.MediaPlayer.State == MediaState.Playing)
{               
    MessageBoxResult Choice;               
    Choice = MessageBox.Show("Media is currently playing, do you want to stop it?", "Stop Player", MessageBoxButton.OKCancel);
    if (Choice == MessageBoxResult.OK)
        mediaElement1.Play(); 
}

If the user allows or disallows the media to be played you must put checks in your JavaScript for this. You will fail certification again if the user says "Cancel" and you play music anyway.

There is more information on the topic here.

Upvotes: 0

Related Questions