提交 72125551 编写于 作者: J Jerome Laban

chore: Adjust fullscreen support

上级 ec0279da
......@@ -30,9 +30,7 @@ public partial class GtkMediaPlayer : FrameworkElement
private VideoView? _videoView;
private Uri? _mediaPath;
private bool _isEnding;
private bool _isPlaying;
private bool _isLoopingEnabled;
private long _currentPositionBeforeFullscreenChange;
private double _playbackRate;
private Rect _transportControlsBounds;
private Windows.UI.Xaml.Media.Stretch _stretch = Windows.UI.Xaml.Media.Stretch.Uniform;
......@@ -154,84 +152,19 @@ public partial class GtkMediaPlayer : FrameworkElement
public void ExitFullScreen()
{
if (EnsureMediaPlayerAndVideoView())
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug("ExitFullScreen");
}
_isPlaying = _mediaPlayer.State == VLCState.Playing;
_currentPositionBeforeFullscreenChange = _mediaPlayer.Time;
Stop();
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await Initialize();
UpdateMedia();
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
UpdateVideoStretch();
Play();
Pause();
CurrentPosition = (double)_currentPositionBeforeFullscreenChange;
if (_isPlaying)
{
Play();
}
});
});
}
else
{
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug("Unable to exit fullscreen, the player is not ready yet");
}
this.Log().Debug("ExitFullScreen");
}
}
public void RequestFullScreen()
{
if (EnsureMediaPlayerAndVideoView())
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug("RequestFullScreen");
}
_isPlaying = _mediaPlayer.State == VLCState.Playing;
_currentPositionBeforeFullscreenChange = _mediaPlayer.Time;
Stop();
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await Initialize();
UpdateMedia();
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
UpdateVideoStretch();
Play();
Pause();
CurrentPosition = (double)_currentPositionBeforeFullscreenChange;
if (_isPlaying)
{
Play();
}
});
});
}
else
{
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug("Unable to request fullscreen, the player is not ready yet");
}
this.Log().Debug("RequestFullScreen");
}
}
public void Stop()
......
......@@ -26,14 +26,15 @@ namespace Uno.UI.Media;
public partial class GtkMediaPlayer
{
private Task? _initializationTask;
private MediaPlayerElement? _mpe;
public event EventHandler<object>? OnSourceFailed;
public event EventHandler<object>? OnSourceEnded;
public event EventHandler<object>? OnMetadataLoaded;
public event EventHandler<object>? OnTimeUpdate;
public event EventHandler<object>? OnSourceLoaded;
private Task? _initializationTask;
private async Task Initialize()
{
if (_initializationTask is null)
......@@ -112,12 +113,24 @@ public partial class GtkMediaPlayer
private void OnVideoViewVideoSurfaceInteraction(object? sender, EventArgs e)
{
if (_owner.FindFirstParent<MediaPlayerElement>() is { } mpe)
UpdateMediaPlayerElementReference();
if (_mpe is not null)
{
_mpe.TransportControls.Show();
}
else
{
mpe.TransportControls.Show();
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug($"Unable to find a MediaPlayerElement instance to show the transport controls");
}
}
}
private void UpdateMediaPlayerElementReference()
=> _mpe ??= _owner.FindFirstParent<MediaPlayerElement>();
private void OnSourceVideoLoaded(object? sender, EventArgs e)
{
if (_videoView != null)
......
......@@ -68,8 +68,8 @@ namespace LibVLCSharp.GTK
Core.Initialize();
Realized += (s, e) => Attach();
Unrealized += (s, e) => Detach();
Realized += (s, e) => AttachToWidget();
Unrealized += (s, e) => DetachFromWidget();
}
internal void SetVisible(bool visible)
......@@ -99,24 +99,32 @@ namespace LibVLCSharp.GTK
return;
}
Detach();
DestroyChildWindow();
_mediaPlayer = value;
Attach();
CreateChildWindow();
}
}
private void Attach()
private void CreateChildWindow()
{
if (!IsRealized || _mediaPlayer == null)
if (_mediaPlayer == null)
{
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug($"Unable to attach player (IsRealized:{IsRealized}, _mediaPlayer: {_mediaPlayer is not null})");
this.Log().Debug($"Unable to attach player (_mediaPlayer: {_mediaPlayer is not null})");
}
return;
}
if (_videoWindow is not null)
{
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug($"VideoView is already attached, skipping");
}
}
if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug("Attaching player");
......@@ -149,13 +157,29 @@ namespace LibVLCSharp.GTK
// Hide it immediately so it does not show outside of our own window
_videoWindow.Hide();
// Reparent the window to the current window, so it appears inside.
_videoWindow.Window.Reparent(Toplevel.Window, 0, 0);
AssignWindowId();
// Show the window once the ID has been associated in libVLC
_videoWindow.Show();
AttachToWidget();
}
private void AttachToWidget()
{
if (IsRealized && _videoWindow is not null)
{
// Reparent the window to the current window, so it appears inside.
_videoWindow.Window.Reparent(Toplevel.Window, 0, 0);
// Show the window once the ID has been associated in libVLC
_videoWindow.Show();
}
}
private void DetachFromWidget()
{
if (!IsRealized && _videoWindow is not null)
{
_videoWindow.Hide();
}
}
private void OnVideoWindowMotionNotifyEvent(object o, MotionNotifyEventArgs args)
......@@ -203,7 +227,19 @@ namespace LibVLCSharp.GTK
}
}
void Detach()
private void DestroyChildWindow()
{
RemoveWindowId();
if (_videoWindow is not null)
{
_videoWindow.Hide();
_videoWindow.Destroy();
_videoWindow = null;
}
}
private void RemoveWindowId()
{
if (_mediaPlayer is not null)
{
......@@ -224,13 +260,6 @@ namespace LibVLCSharp.GTK
throw new PlatformNotSupportedException();
}
}
if (_videoWindow is not null)
{
_videoWindow.Hide();
_videoWindow.Destroy();
_videoWindow = null;
}
}
internal void Arrange(Gdk.Rectangle value)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册