Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pause media playback when navigating away from mediaplay page #1338

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions WinUIGallery/ControlPages/MediaPlayerElementPage.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Page x:Class="AppUIBasics.ControlPages.MediaPlayerElementPage"
<Page x:Class="AppUIBasics.ControlPages.MediaPlayerElementPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:AppUIBasics"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<StackPanel>
<local:ControlExample x:Name="Example1" HeaderText="A MediaPlayerElement with transport controls.">
<local:ControlExample.Example>
<MediaPlayerElement Source="ms-appx:///Assets/SampleMedia/ladybug.wmv" MaxWidth="400" AutoPlay="False"
<MediaPlayerElement x:Name="Player1" Source="ms-appx:///Assets/SampleMedia/ladybug.wmv" MaxWidth="400" AutoPlay="False"
AreTransportControlsEnabled="True" />
</local:ControlExample.Example>
<local:ControlExample.Xaml>
Expand All @@ -20,7 +20,7 @@
</local:ControlExample>
<local:ControlExample x:Name="Example2" HeaderText="A MediaPlayerElement that autoplays the video.">
<local:ControlExample.Example>
<MediaPlayerElement Source="ms-appx:///Assets/SampleMedia/fishes.wmv" MaxWidth="400" AutoPlay="True" />
<MediaPlayerElement x:Name="Player2" Source="ms-appx:///Assets/SampleMedia/fishes.wmv" MaxWidth="400" AutoPlay="True" />
</local:ControlExample.Example>
<local:ControlExample.Xaml>
<x:String xml:space="preserve">
Expand Down
17 changes: 16 additions & 1 deletion WinUIGallery/ControlPages/MediaPlayerElementPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -21,5 +21,20 @@ public MediaPlayerElementPage()
{
this.InitializeComponent();
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
// Needed if this page is getting cached due to the navigation stack.
Player2.MediaPlayer.Play();
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
// Pause media playback since we are no longer visible to the user
Player1.MediaPlayer.Pause();
Player2.MediaPlayer.Pause();
}
}
}