-
-
Notifications
You must be signed in to change notification settings - Fork 266
/
Copy pathVideoViewRenderer.cs
66 lines (58 loc) · 2.04 KB
/
VideoViewRenderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using LibVLCSharp.Forms.Platforms.GTK;
using LibVLCSharp.Forms.Shared;
using LibVLCSharp.Shared;
using Xamarin.Forms;
using Xamarin.Forms.Platform.GTK;
[assembly: ExportRenderer(typeof(LibVLCSharp.Forms.Shared.VideoView), typeof(VideoViewRenderer))]
namespace LibVLCSharp.Forms.Platforms.GTK
{
/// <summary>
/// Xamarin.Forms renderer for the VideoView on GTK
/// </summary>
public class VideoViewRenderer : ViewRenderer<LibVLCSharp.Forms.Shared.VideoView, LibVLCSharp.GTK.VideoView>
{
LibVLCSharp.GTK.VideoView? _videoView;
/// <summary>
/// Native control management during lifecycle events
/// </summary>
/// <param name="e">lifecycle event</param>
protected override void OnElementChanged(ElementChangedEventArgs<VideoView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
_videoView = new LibVLCSharp.GTK.VideoView();
SetNativeControl(_videoView);
}
if (e.OldElement != null)
{
e.OldElement.MediaPlayerChanging -= OnMediaPlayerChanging;
}
if (e.NewElement != null)
{
e.NewElement.MediaPlayerChanging += OnMediaPlayerChanging;
if (Control!.MediaPlayer != e.NewElement.MediaPlayer)
{
OnMediaPlayerChanging(this, new MediaPlayerChangingEventArgs(Control.MediaPlayer, e.NewElement.MediaPlayer));
}
}
}
private void OnMediaPlayerChanging(object? sender, MediaPlayerChangingEventArgs e)
{
if (Control == null)
{
return;
}
Control.MediaPlayer = e.NewMediaPlayer;
}
/// <summary>
/// Dispose of the videoview, if any
/// </summary>
/// <param name="disposing"></param>
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_videoView?.Dispose();
}
}
}