Skip to content

Commit

Permalink
fix(mediaplayer): Fix invalid stop of the player when toggling the fu…
Browse files Browse the repository at this point in the history
…llscreen mode.
  • Loading branch information
jeremiethibeault committed Apr 27, 2020
1 parent 7764769 commit efe2e89
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
33 changes: 21 additions & 12 deletions src/Uno.UI/UI/Xaml/Controls/MediaPlayer/MediaPlayerElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,38 @@ private static void OnIsFullWindowChanged(DependencyObject sender, DependencyPro

private void ToogleFullScreen(bool showFullscreen)
{
if (showFullscreen)
try
{
ApplicationView.GetForCurrentView().TryEnterFullScreenMode();
_mediaPlayerPresenter.IsTogglingFullscreen = true;

if (showFullscreen)
{
ApplicationView.GetForCurrentView().TryEnterFullScreenMode();

#if __ANDROID__
this.RemoveView(_layoutRoot);
this.RemoveView(_layoutRoot);
#elif __IOS__
_layoutRoot.RemoveFromSuperview();
_layoutRoot.RemoveFromSuperview();
#endif

Windows.UI.Xaml.Window.Current.DisplayFullscreen(_layoutRoot);
}
else
{
ApplicationView.GetForCurrentView().ExitFullScreenMode();
Windows.UI.Xaml.Window.Current.DisplayFullscreen(_layoutRoot);
}
else
{
ApplicationView.GetForCurrentView().ExitFullScreenMode();

Windows.UI.Xaml.Window.Current.DisplayFullscreen(null);
Windows.UI.Xaml.Window.Current.DisplayFullscreen(null);

#if __ANDROID__
this.AddView(_layoutRoot);
this.AddView(_layoutRoot);
#elif __IOS__
this.Add(_layoutRoot);
this.Add(_layoutRoot);
#endif
}
}
finally
{
_mediaPlayerPresenter.IsTogglingFullscreen = false;
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/MediaPlayer/MediaPlayerPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,20 @@ public MediaPlayerPresenter() : base()
{
}

/// <summary>
/// Indicates whether or not the player is currently toggling the fullscreen mode.
/// </summary>
internal bool IsTogglingFullscreen { get; set; }

protected override void OnUnloaded()
{
MediaPlayer.Stop();
// The control will get unloaded when going to full screen mode.
// Similar to UWP, the video should keep playing while changing mode.
if (!IsTogglingFullscreen)
{
MediaPlayer.Stop();
}

base.OnUnloaded();
}

Expand Down

0 comments on commit efe2e89

Please sign in to comment.