2

I have a UWP app with NavigationView that handles the backstack in different frames. The back press is handled in my MainPage.xaml by the function:

private bool On_BackRequested()
        {
            if (contentFrame.CanGoBack)
            {
                contentFrame.GoBack();
                Debug.WriteLine(contentFrame.);
                return true;
            }
            return false;
        }

But the problem arises when there is a MediaPlayerElement playing videos in a frame. The back press is handled properly but the video doesn't stop playing (I know this because the audio from the video is still playing in the background).

How can I stop the video playback during the back press method? Can I access a certain function from the childframe to stop the video?

szskdgi
  • 295
  • 2
  • 17

1 Answers1

2

I found a solution using Stop YouTube Video on Back Button of Windows Metro App 8.1. I used an unloaded function in the constructor of the child frame.

mediaPlayer.Unloaded += mediaPlayer_UnLoaded;

And also added a function:

private void mediaPlayer_UnLoaded(object sender, RoutedEventArgs e)
        {
            mediaPlayer.MediaPlayer.Pause();
        }
szskdgi
  • 295
  • 2
  • 17