0

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?

joe
  • 16,988
  • 36
  • 94
  • 131
  • As in, are you using PhoneGap or some other middleware to dev in Javascript? May have a bearing on your question. Tags help target your audience. –  Dec 12 '12 at 01:33

2 Answers2

1

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.

0

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.

  • 1
    Dear lawd, don't even *ask* me if I want to stop my playlist. I don't want to listen to your (nothing personal) crappy music. Also, the OP mentions "javascript", you think he's using PhoneGap or something similar? Would this work in PhoneGap? Also also, you'd want to check this once, on load. –  Dec 11 '12 at 20:47
  • Jeremiah, thank you for your thoughtful answer. But my question was not how to stop my app from playing music, it was how how to have my app not stop the background music. In iOS and Android apps can still play sound effects while background music is playing, perhaps MS does not support this. – joe Dec 11 '12 at 20:59
  • But thanks again, I may need to use your solution if I cannot find a better option. – joe Dec 11 '12 at 21:08
  • Joe, MSFT does not allow per your above statement for Windows Phone devices. The solution I have presented is exactly what you are looking for. Scenario: I am a user with a Windows Phone. I play music from the Music player on the phone. While music is playing I open your app (this is the point (onload) where the code is to be called) and I get prompted "Media is playing, do you want to stop it?" -- If I, the user, say "Yes, stop it" then you (the programmer) have the go ahead to play any music you'd like. If I say "No" you must not override this otherwise you will fail MS store certification. – Jeremiah Isaacson Dec 11 '12 at 22:05
  • It is a disappointing decision by MS as iOS and Android users often play apps with sound effects while listening to music in the background. – joe Dec 11 '12 at 22:40
  • Your point is debatable. The other platforms have their flaws and in my opinion they are far greater than Windows Phone. In a related topic iOS browser doesn't allow onLoad JavaScript to play, all of which is a design choice to make the user experience better. I think that the Msft design choice is a good one as what if I would prefer to have my own soundtrack to a game or while browsing? On Windows Phone you (the user) have a choice, I'd rather have a choice. I encourage you to make a truly native app as your users will appreciate it. – Jeremiah Isaacson Dec 11 '12 at 23:01
  • With XNA audio (Windows Phone 7) you can play audio and sound effects. – Jeremiah Isaacson Dec 11 '12 at 23:02
  • @joe Wp7/7.5/8 has its own limits like everybody else. Sorry if anybody took my prev comment as an offense. As a WP7.1 user, I absolutely HATE when apps nuke my playlist for their own. Glad the WP team keeps devs from stomping on what I am currently listening to. Which is what I'm listening to; that's why I'm listening. –  Dec 12 '12 at 01:32
  • ios has the same capability (http://stackoverflow.com/questions/12475867/ios-how-do-i-detect-if-music-is-playing-in-any-background-music-app), they just don't enforce it on submition. – joe Dec 12 '12 at 14:50