Stop background audio when app start Win phone 8

114 views Asked by At

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.

0

There are 0 answers