0

In my Windows Phone 7 and 7.5 apps I used to prompt a message box when the app was launched if the user was already playing music, to notify the user to stop current music to play the sounds, or to exit the app, this was working, but when I coded from the beginning for Windows Phone 8, for some reason this code doesn't work, if you are playing a sound, instead to prompt the notification, the apps opens and close itself.

This is the code I was using:

private void Application_Launching(object sender, LaunchingEventArgs e)
    {
        FrameworkDispatcher.Update();
        if (MediaPlayer.GameHasControl != true)
        {
            if (MessageBox.Show("This application requires play sounds and stop your     currently playlist", "Information",
                MessageBoxButton.OK) == MessageBoxResult.OK)
            {
                MediaPlayer.Stop();
                FrameworkDispatcher.Update();
            }
        }
    }

I'm pretty sure must be some change in the Api with the MediaPlayer? I couldn't find any information about that, someone knows how can I fix that?

Thanks!!!

Snake-leaf
  • 7
  • 1
  • 4
  • http://stackoverflow.com/questions/20958068/windows-phone-8-2-background-audios-clash-and-both-of-the-app-terminates/20959144#20959144 - this works fine in my case. Have you managed to debug where the Apps exits? Any exception? – Romasz Jan 08 '14 at 19:54
  • Yes, the error it is exactly the one that Walt Ritscher says, if I move the messagebox into every section will work ok, but not in the application_launching, I can't find the right way to display it when the application launch. – Snake-leaf Jan 09 '14 at 05:27
  • MainPage OnNavigatedTo or other page where your App starts? – Romasz Jan 09 '14 at 06:42

1 Answers1

1

As you guessed,there are some changes in APIs.

First thing I notice, calling MessageBox.Show(string) from the Application_Launching event causes an exception. You app is probably shutting down due to an unhandled exception.

From MSDN: "If you call Show(String) method from the app Activated and Launching event handlers an InvalidOperationException is thrown with the message Error Displaying MessageBox."

EDIT: The documentation on MSDN is unclear whether calling .Show(string, string, messageBoxButton) raises the same exception.

App platform compatibility for Windows Phone

Walt Ritscher
  • 6,977
  • 1
  • 28
  • 35
  • I moved it from Application_Launching to – Snake-leaf Jan 09 '14 at 05:44
  • Thank you for your answer, that is exactly the problem (you explained better than me), Is quite unclear the Show(string) in Windows Phone 8. To solve temporarily I put it when the mainpage is loaded, looks like it fixed the problem, now I need to check if it goes through certification process. Thanks! – Snake-leaf Jan 09 '14 at 08:30
  • @Snake-leaf Only watch out because MainPage can be constructed/navigated several Times not only when you start the App. And if Walt's answer solved your problem don't forget to accept it (this green tick beside it). – Romasz Jan 09 '14 at 09:03
  • @Romasz Will check that today later when I get back home, thanks! – Snake-leaf Jan 09 '14 at 22:28