Skip to content

Support for MediaPlayerElement/MediaPlayer - SKIA - #12198

Merged
jeromelaban merged 73 commits into
masterfrom
dev/ramr/mediaPlayerSkia
May 26, 2023
Merged

jeromelaban merged 73 commits into
masterfrom
dev/ramr/mediaPlayerSkia

Conversation

@rafael-rosa-knowcode

@rafael-rosa-knowcode rafael-rosa-knowcode commented May 8, 2023 •

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): closes #

PR Type

What kind of change does this PR introduce?

Support for MediaPlayerElement/MediaPlayer on Skia GTK

What is the current behavior?

Skia GTK do not play MediaPlayerElement

What is the new behavior?

Play MediaPlayerElement/MediaPlayer and have all features.

PR Checklist Of Features

Not Work

  • Issue related to the click on the VideoView. We are unable to click on Video and allow events. So we are not able to show the TransportControl and navigation control features.
  • When we enter in Fullscreen mode there is not space to click and back to the controls.
  • When Fit to the MediaPlayer size, we have just one pixel to bring the controls back.

image

OK - working

  • Pause
  • Play
  • Stop
  • Volume
  • IsCompact
  • ShowAndHideAutomatically
  • Mute
  • FastForward
  • FastRewind
  • IsFullWindow
  • NextTrack
  • PreviousTrack
  • PlaybackRate
  • Repeat
  • Seek
  • SkipBackward
  • SkipForward
  • Zoom
  • DragDrop Timeline
  • Click Timeline

Show and Enable functionality Work

  • IsFastForwardButtonVisible
  • IsFastForwardEnabled
  • IsFastRewindButtonVisible
  • IsFastRewindEnabled
  • IsFullWindowButtonVisible
  • IsFullWindowEnabled
  • IsNextTrackButtonVisible
  • IsPlaybackRateButtonVisible
  • IsPlaybackRateEnabled
  • IsPreviousTrackButtonVisible
  • IsRepeatButtonVisible
  • IsRepeatEnabled
  • IsSeekBarVisible
  • IsSeekEnabled
  • IsSkipBackwardButtonVisible
  • IsSkipBackwardEnabled
  • IsSkipForwardButtonVisible
  • IsSkipForwardEnabled
  • IsStopButtonVisible
  • IsStopEnabled
  • IsVolumeButtonVisible
  • IsVolumeEnabled
  • IsZoomButtonVisible
  • IsZoomEnabled
  • IsCompactOverlayButtonVisible
  • IsCompactOverlayEnabled

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable): #12240

@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label May 8, 2023
Comment thread src/Uno.UI-Skia-only.slnf Resolved
@nickrandolph
nickrandolph force-pushed the dev/ramr/mediaPlayerSkia branch 2 times, most recently from 9368963 to 9dc51d4 Compare May 9, 2023 08:04

@Youssef1313 Youssef1313 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rafael-rosa-knowcode I was discussing

_timelineContainer?.SetBinding(Border.IsEnabledProperty, new Binding { Path = "IsSeekEnabled", Source = this, Mode = BindingMode.OneWay, FallbackValue = true });
with @nickrandolph

Border isn't supposed to have IsEnabled and it's being removed as part of the breaking changes. We think this line should set IsEnabled for ProgressSlider rather than the border.

I'm making the change in the breaking changes branch to unblock merging master to it: 1f8dffa, but consider doing it for master as well.

@rafael-rosa-knowcode
rafael-rosa-knowcode force-pushed the dev/ramr/mediaPlayerSkia branch from 161cb44 to 12a0399 Compare May 15, 2023 17:38
@rafael-rosa-knowcode
rafael-rosa-knowcode force-pushed the dev/ramr/mediaPlayerSkia branch from be5038d to 0b50d0c Compare May 17, 2023 14:12
Comment on lines +268 to +399
{
if (_videoView != null &&
_mediaPlayer != null &&
_mediaPlayer.Media != null &&
_mediaPlayer.Media.Mrl != null &&
_videoContainer is not null)
{
if (this.ActualHeight <= 0 || this.ActualWidth <= 0)
{
CheckUpdatedRequested();
return;
}

var playerHeight = (double)this.ActualHeight - _transportControlsBounds.Height;
var playerWidth = (double)this.ActualWidth;

_mediaPlayer.Media.Parse(MediaParseOptions.ParseNetwork);

_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
if (_mediaPlayer != null && _mediaPlayer.Media != null)
{
var videoTrack = _mediaPlayer.Media.Tracks.FirstOrDefault(track => track.TrackType == TrackType.Video);
if (_mediaPlayer.Media.Tracks.Any(track => track.TrackType == TrackType.Video))
{
var videoSettings = videoTrack.Data.Video;
var videoWidth = videoSettings.Width;
var videoHeight = videoSettings.Height;

// From: https://github.com/videolan/libvlcsharp/blob/bca0a53fe921e6f1f745e4e3ac83a7bd3b2e4a9d/src/LibVLCSharp/Shared/MediaPlayerElement/AspectRatioManager.cs#L188
videoWidth = videoWidth * videoSettings.SarNum / videoSettings.SarDen;

UpdateVideoSizeAllocate(playerHeight, playerWidth, videoHeight, videoWidth);
}
else
{
CheckUpdatedRequested();
}
}
else
{
CheckUpdatedRequested();
}
});
}
else
{
CheckUpdatedRequested();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{
if (_videoView != null &&
_mediaPlayer != null &&
_mediaPlayer.Media != null &&
_mediaPlayer.Media.Mrl != null &&
_videoContainer is not null)
{
if (this.ActualHeight <= 0 || this.ActualWidth <= 0)
{
CheckUpdatedRequested();
return;
}
var playerHeight = (double)this.ActualHeight - _transportControlsBounds.Height;
var playerWidth = (double)this.ActualWidth;
_mediaPlayer.Media.Parse(MediaParseOptions.ParseNetwork);
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
if (_mediaPlayer != null && _mediaPlayer.Media != null)
{
var videoTrack = _mediaPlayer.Media.Tracks.FirstOrDefault(track => track.TrackType == TrackType.Video);
if (_mediaPlayer.Media.Tracks.Any(track => track.TrackType == TrackType.Video))
{
var videoSettings = videoTrack.Data.Video;
var videoWidth = videoSettings.Width;
var videoHeight = videoSettings.Height;
// From: https://github.com/videolan/libvlcsharp/blob/bca0a53fe921e6f1f745e4e3ac83a7bd3b2e4a9d/src/LibVLCSharp/Shared/MediaPlayerElement/AspectRatioManager.cs#L188
videoWidth = videoWidth * videoSettings.SarNum / videoSettings.SarDen;
UpdateVideoSizeAllocate(playerHeight, playerWidth, videoHeight, videoWidth);
}
else
{
CheckUpdatedRequested();
}
}
else
{
CheckUpdatedRequested();
}
});
}
else
{
CheckUpdatedRequested();
}
{
if (_videoView is not null &&
_mediaPlayer?.Media is { Mrl: not null } media
_videoContainer is not null)
{
if (this.ActualHeight <= 0 || this.ActualWidth <= 0)
{
CheckUpdatedRequested();
return;
}
var playerHeight = (double)this.ActualHeight - _transportControlsBounds.Height;
var playerWidth = (double)this.ActualWidth;
media.Parse(MediaParseOptions.ParseNetwork);
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
if (media != _mediaPlayer?.Media)
{
return; // The media has been modified, abort async operation
}
if (media.Tracks.FirstOrDefault(track => track.TrackType == TrackType.Video) is { } videoTrack)
{
var videoSettings = videoTrack.Data.Video;
var videoWidth = videoSettings.Width;
var videoHeight = videoSettings.Height;
// From: https://github.com/videolan/libvlcsharp/blob/bca0a53fe921e6f1f745e4e3ac83a7bd3b2e4a9d/src/LibVLCSharp/Shared/MediaPlayerElement/AspectRatioManager.cs#L188
videoWidth = videoWidth * videoSettings.SarNum / videoSettings.SarDen;
UpdateVideoSizeAllocate(playerHeight, playerWidth, videoHeight, videoWidth);
}
else
{
CheckUpdatedRequested();
}
});
}
else
{
CheckUpdatedRequested();
}
  • As you are running async, you should capture the media variables to make sure that it's not altered while deferring
  • You are searching for the video track (videoTrack) in media, and the enumerating a second time to validate the you found something instead of validating that videoTrack is not null

You should also keep a reference of your async taks (the _) and make sure to clear it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change do not work.
The media != _mediaPlayer?.Media is always different.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me the media != _mediaPlayer?.Media is always false is a red flag. It could be either:

  • We are scheduling an async task for a given media, but it changes before we are able to execute that task ... and we will probably re-schedule a new task soon for the new media
  • More probably the _mediaPlayer?.Media is creating a new instance of LibVLCSharp.[..].Media on each get and that class does not implement equality operators. Then we should definitely keep a reference on the media like I did instead of getting it everytime, and change the check I did to protect our-self from the first case by either:
    • Comparing media.Mrl instead of instances (we need to check if its a full Mrl that contains all infos about the media)
    • (Preferred) Using a CancellationToken for all async operation related to the media and make sure to cancel it when the media changes.

@jeromelaban
jeromelaban force-pushed the dev/ramr/mediaPlayerSkia branch from b34245b to ef9dea5 Compare May 25, 2023 15:31
@jeromelaban
jeromelaban marked this pull request as ready for review May 25, 2023 20:47
Comment on lines +316 to +318
var videoTrack = _mediaPlayer.Media.Tracks.FirstOrDefault(track => track.TrackType == TrackType.Video);

if (_mediaPlayer.Media.Tracks.Any(track => track.TrackType == TrackType.Video))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My previous comment here has not been addressed yet. There is something that we need to understand and fix / workaround #12198 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address separately

@jeromelaban
jeromelaban merged commit 27c7e13 into master May 26, 2023
@jeromelaban
jeromelaban deleted the dev/ramr/mediaPlayerSkia branch May 26, 2023 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/skia ✏️ Categorizes an issue or PR as relevant to Skia

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants