Commit a939717a authored by Martin Finkel's avatar Martin Finkel

Update Forms sample project

parent f3e4836c
......@@ -2,6 +2,11 @@
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:shared="clr-namespace:LibVLCSharp.Forms.Shared;assembly=LibVLCSharp.Forms"
xmlns:local="clr-namespace:LibVLCSharp.Forms.Sample"
x:Class="LibVLCSharp.Forms.Sample.MainPage">
<shared:VideoView x:Name="videoView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
<ContentPage.BindingContext>
<local:MainViewModel />
</ContentPage.BindingContext>
<shared:VideoView MediaPlayer="{Binding MediaPlayer}" x:Name="videoView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
</ContentPage>
using LibVLCSharp.Shared;
using System.Diagnostics;
using Xamarin.Forms;
namespace LibVLCSharp.Forms.Sample
{
public partial class MainPage : ContentPage
{
MainViewModel _vm;
public MainPage()
{
InitializeComponent();
......@@ -14,8 +16,22 @@ namespace LibVLCSharp.Forms.Sample
{
base.OnAppearing();
videoView.MediaPlayer.Play(new Media(videoView.LibVLC,
"http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", Media.FromType.FromLocation));
videoView.MediaPlayerChanged += VideoView_MediaPlayerChanged;
_vm = BindingContext as MainViewModel;
_vm.PropertyChanged += Vm_PropertyChanged;
_vm.Initialize();
}
private void Vm_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if(e.PropertyName.Equals(nameof(_vm.MediaPlayer)))
Trace.WriteLine("MediaPlayer change raised from ViewModel.Propertychanged");
}
private void VideoView_MediaPlayerChanged(object sender, Shared.MediaPlayerChangedEventArgs e)
{
Trace.WriteLine("VideoView_MediaPlayerChanged");
}
}
}
\ No newline at end of file
using LibVLCSharp.Shared;
using System.ComponentModel;
namespace LibVLCSharp.Forms.Sample
{
public class MainViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
LibVLC _libVLC;
private MediaPlayer _mediaPlayer;
public MediaPlayer MediaPlayer
{
get => _mediaPlayer;
private set => Set(nameof(MediaPlayer), ref _mediaPlayer, value);
}
private void Set<T>(string propertyName, ref T field, T value)
{
if (field == null && value != null || field != null && !field.Equals(value))
{
field = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public void Initialize()
{
Core.Initialize();
_libVLC = new LibVLC();
MediaPlayer = new MediaPlayer(_libVLC)
{
Media = new Media(_libVLC,
"http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4",
Media.FromType.FromLocation)
};
MediaPlayer.Play();
}
}
}
\ 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