Commit f3e4836c authored by Martin Finkel's avatar Martin Finkel

Update LibVLCSharp.Forms to the new VideoView API

parent 43c7939d
......@@ -7,37 +7,29 @@ namespace LibVLCSharp.Forms.Platforms.WPF
{
public class VideoViewRenderer : ViewRenderer<VideoView, LibVLCSharp.WPF.VideoView>
{
LibVLCSharp.WPF.VideoView _videoView;
protected override void OnElementChanged(ElementChangedEventArgs<VideoView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
_videoView = new LibVLCSharp.WPF.VideoView();
SetNativeControl(_videoView);
SetNativeControl(new LibVLCSharp.WPF.VideoView());
}
if (e.OldElement != null)
{
e.OldElement.MediaPlayerChanged -= OnMediaPlayerChanged;
}
if (e.NewElement != null)
{
UpdateMediaPlayer();
UpdateLibVLC();
e.NewElement.MediaPlayerChanged += OnMediaPlayerChanged;
}
base.OnElementChanged(e);
}
void UpdateMediaPlayer()
{
Element.MediaPlayer = Control.MediaPlayer;
}
void UpdateLibVLC()
private void OnMediaPlayerChanged(object sender, MediaPlayerChangedEventArgs e)
{
Element.LibVLC = Control.LibVLC;
Control.MediaPlayer = e.NewMediaPlayer;
}
}
}
\ No newline at end of file
......@@ -11,8 +11,6 @@ namespace LibVLCSharp.Forms.Platforms.Android
{
public class VideoViewRenderer : ViewRenderer<LibVLCSharp.Forms.Shared.VideoView, LibVLCSharp.Platforms.Android.VideoView>
{
LibVLCSharp.Platforms.Android.VideoView _videoView;
public VideoViewRenderer(Context context) : base(context)
{
}
......@@ -23,27 +21,23 @@ namespace LibVLCSharp.Forms.Platforms.Android
if (Control == null)
{
_videoView = new LibVLCSharp.Platforms.Android.VideoView(Context, Element.CliOptions);
SetNativeControl(_videoView);
Element.LibVLC = Control.LibVLC;
Element.MediaPlayer = Control.MediaPlayer;
SetNativeControl(new LibVLCSharp.Platforms.Android.VideoView(Context));
}
if (e.OldElement != null)
{
e.OldElement.MediaPlayerChanged -= OnMediaPlayerChanged;
}
if (e.NewElement != null)
{
e.NewElement.MediaPlayerChanged += OnMediaPlayerChanged;
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_videoView.Dispose();
private void OnMediaPlayerChanged(object sender, MediaPlayerChangedEventArgs e)
{
Control.MediaPlayer = e.NewMediaPlayer;
}
}
}
\ No newline at end of file
......@@ -9,35 +9,29 @@ namespace LibVLCSharp.Forms.Platforms.Mac
{
public class VideoViewRenderer : ViewRenderer<LibVLCSharp.Forms.Shared.VideoView, LibVLCSharp.Platforms.Mac.VideoView>
{
LibVLCSharp.Platforms.Mac.VideoView _videoView;
protected override void OnElementChanged(ElementChangedEventArgs<VideoView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
_videoView = new LibVLCSharp.Platforms.Mac.VideoView(Element.CliOptions);
SetNativeControl(_videoView);
Element.LibVLC = Control.LibVLC;
Element.MediaPlayer = Control.MediaPlayer;
SetNativeControl(new LibVLCSharp.Platforms.Mac.VideoView());
}
if (e.OldElement != null)
{
e.OldElement.MediaPlayerChanged -= OnMediaPlayerChanged;
}
if (e.NewElement != null)
{
e.NewElement.MediaPlayerChanged += OnMediaPlayerChanged;
}
}
protected override void Dispose(bool disposing)
private void OnMediaPlayerChanged(object sender, MediaPlayerChangedEventArgs e)
{
base.Dispose(disposing);
_videoView.Dispose();
Control.MediaPlayer = e.NewMediaPlayer;
}
}
}
\ No newline at end of file
......@@ -9,35 +9,29 @@ namespace LibVLCSharp.Forms.Platforms.iOS
{
public class VideoViewRenderer : ViewRenderer<LibVLCSharp.Forms.Shared.VideoView, LibVLCSharp.Platforms.iOS.VideoView>
{
LibVLCSharp.Platforms.iOS.VideoView _videoView;
protected override void OnElementChanged(ElementChangedEventArgs<VideoView> e)
{
base.OnElementChanged(e);
if(Control == null)
{
_videoView = new LibVLCSharp.Platforms.iOS.VideoView(Element.CliOptions);
SetNativeControl(_videoView);
Element.LibVLC = Control.LibVLC;
Element.MediaPlayer = Control.MediaPlayer;
SetNativeControl(new LibVLCSharp.Platforms.iOS.VideoView());
}
if (e.OldElement != null)
{
e.OldElement.MediaPlayerChanged -= OnMediaPlayerChanged;
}
if (e.NewElement != null)
{
}
e.NewElement.MediaPlayerChanged += OnMediaPlayerChanged;
}
}
protected override void Dispose(bool disposing)
private void OnMediaPlayerChanged(object sender, MediaPlayerChangedEventArgs e)
{
base.Dispose(disposing);
_videoView.Dispose();
Control.MediaPlayer = e.NewMediaPlayer;
}
}
}
\ No newline at end of file
using System;
namespace LibVLCSharp.Forms.Shared
{
public class MediaPlayerChangedEventArgs : EventArgs
{
public MediaPlayerChangedEventArgs(LibVLCSharp.Shared.MediaPlayer oldMediaPlayer, LibVLCSharp.Shared.MediaPlayer newMediaPlayer)
{
OldMediaPlayer = oldMediaPlayer;
NewMediaPlayer = newMediaPlayer;
}
public LibVLCSharp.Shared.MediaPlayer OldMediaPlayer { get; }
public LibVLCSharp.Shared.MediaPlayer NewMediaPlayer { get; }
}
}
\ No newline at end of file
using LibVLCSharp.Shared;
using System;
using System.Diagnostics;
using Xamarin.Forms;
namespace LibVLCSharp.Forms.Shared
......@@ -6,21 +7,26 @@ namespace LibVLCSharp.Forms.Shared
public class VideoView : View
{
/// <summary>
/// Constructor with extra configuration
/// Raised when a new MediaPlayer is set and attached to the view
/// </summary>
/// <param name="cliOptions">https://wiki.videolan.org/VLC_command-line_help/</param>
public VideoView(string[] cliOptions)
public event EventHandler<MediaPlayerChangedEventArgs> MediaPlayerChanged;
public static readonly BindableProperty MediaPlayerProperty = BindableProperty.Create(nameof(MediaPlayer),
typeof(LibVLCSharp.Shared.MediaPlayer),
typeof(VideoView),
propertyChanged: OnMediaPlayerChanged);
public LibVLCSharp.Shared.MediaPlayer MediaPlayer
{
CliOptions = cliOptions;
get { return GetValue(MediaPlayerProperty) as LibVLCSharp.Shared.MediaPlayer; }
set { SetValue(MediaPlayerProperty, value); }
}
public VideoView()
private static void OnMediaPlayerChanged(BindableObject bindable, object oldValue, object newValue)
{
var videoView = (VideoView)bindable;
Trace.WriteLine("OnMediaPlayerChanged");
videoView.MediaPlayerChanged?.Invoke(videoView, new MediaPlayerChangedEventArgs(oldValue as LibVLCSharp.Shared.MediaPlayer, newValue as LibVLCSharp.Shared.MediaPlayer));
}
public string[] CliOptions { get; }
public LibVLCSharp.Shared.MediaPlayer MediaPlayer { get; set; }
public LibVLC LibVLC { get; set; }
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment