Stop background audio when app start Win phone 8 - windows-phone-8

I have app that play audio with MediaElement when button is pressed.
But now i have a problem. For example if i play song on mobile and enter the app, when i press that button app breaks and exit...
Now i added at the start page this code:
if (Microsoft.Xna.Framework.Media.MediaPlayer.State == MediaState.Playing)
{
Microsoft.Xna.Framework.Media.MediaPlayer.Pause();
}
And now is the problem that when i start app first time while music i playing, app enter and exit right away, and pause the music. Then if i start app again everything works fine.
But how can i stop or pause the music without exit the app at the first time i start it?
Thanks
UPDATE
I found the answer!
Just add this after Microsoft.Xna.... line in if statment
FrameworkDispatcher.Update();
Now everything works fine.

Related

AIR application crashes when changing stage displayState to fullscreen

A problem started cropping up in my game that hasn't happened before. I have a fullscreen toggle button, and when I press it my game attempts to go into fullscreen but the entire app closes after a few seconds of freezing. No errors are traced when the game closes. I can resize the game just fine (for example the maximize button works as intended), it's just fullscreen that freezes.
I tested the code as shown below:
trace("Before fullscreen");
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
trace("After fullscreen");
Only "Before fullscreen" is traced out, meaning the displayState change freezes the program. Changing the state to NORMAL does not freeze the program, but both FULL_SCREEN and FULL_SCREEN_INTERACTIVE do. The only other information I could find was someone else having the same problem and discovering graphics card problems, but I haven't done anything to change my graphics settings/drivers so I'm not sure if that's the actual problem here.

MediaElement resume / reset on exit (Windows Phone)

I'm experimenting with a simple app that plays an audio file when run (isLooping=true, autoplay=true). It works fine but after closing it and opening it again, the audio file resumes playing the exact same second where I left it the time before, instead of starting over, as it should.
I tried doing audiofile.Stop() before audiofile.Play() but it doesn't work.
I'm guessing that the app never really "closes"? I'm not saving any progress in my app, it just launches and plays a file. That's all it does for now.
Thanks in advance,
call BackgroundAudioPlayer.Instance.Close() in OnNavigatedFrom of your screen and Application_Closing events.

how to close/stop the music which is playing in background in windows phone 8 app

How can i stop the music/song which is currently playing in background from my app?
When user clicks the stop button in my app it should close/stop the music.
How to implement this functionality.
Thanks...
You should be able to detect if an audio stream is playing: Microsoft.Xna.Framework.Media.MediaPlayer.State
But you can't stop it if it's wasn't launched from you app.

Detecting Background Process In Windows Phone 8?

In window Phone 8.
While Music Player is running I just want to run the game.
On that time Game should show some popup.
Like Background Music process is running do you want to continue or stop.
or else Stop the background music of the game.
How could i do that??
From managed you can use MediaPlayer.GameHasControl from the Microsoft.Xna.Framework.Media.MediaPlayer.GameHasControl library: http://blogs.msdn.com/b/oren/archive/2010/12/02/wp7-dev-tip-detecting-whether-or-not-the-user-is-playing-music-in-the-background.aspx

HTML5 Sound Stopping & Iphone

intro: I'm making a html5 game atm, and right now when the user taps the screen i have it playing a sound.
ProblemA: In chrome, the sound plays , but eventually stops playing all together even if i try to refresh the page ( the debug console doesnt show any errors either ) and i have to restart my browser to get the sound to play it again.
ProblemB: Also, the sound doesnt load on my ipod touch. But the game does when i dont load sounds.
i'm not using any api's or librarys. Any links to articles, or such would be helpful.
Edit: Heres some sample code of what im doing.
function loadSound(name,url){
// Increase how many assets we have
_rsvEngineReference.assetCount++;
_rsvEngineReference.assetCollection[name] = new Audio();
_rsvEngineReference.assetCollection[name].src = url
_rsvEngineReference.assetCollection[name].addEventListener('canplaythrough',function(){
_rsvEngineReference.numAssetsLoaded++;
},false)
_rsvEngineReference.assetCollection[name].load();
}
function playSound(name)
{
_rsvEngineReference.assetCollection[name].play()
}