Commit a9a1355d authored by Martin Finkel's avatar Martin Finkel

Forms sample: Dispose resources

parent 26d2e42d
......@@ -4,7 +4,8 @@
xmlns:local="clr-namespace:LibVLCSharp.Forms.Sample.MediaPlayerElement"
xmlns:vlc="clr-namespace:LibVLCSharp.Forms.Shared;assembly=LibVLCSharp.Forms"
x:Class="LibVLCSharp.Forms.Sample.MediaPlayerElement.MainPage"
Appearing="OnAppearing">
Appearing="OnAppearing"
Disappearing="OnDisappearing">
<ContentPage.BindingContext>
<local:MainViewModel />
</ContentPage.BindingContext>
......
......@@ -20,5 +20,11 @@ namespace LibVLCSharp.Forms.Sample.MediaPlayerElement
base.OnAppearing();
((MainViewModel)BindingContext).OnAppearing();
}
void OnDisappearing(object sender, System.EventArgs e)
{
base.OnDisappearing();
((MainViewModel)BindingContext).OnDisappearing();
}
}
}
......@@ -22,6 +22,7 @@ namespace LibVLCSharp.Forms.Sample.MediaPlayerElement
}
private LibVLC _libVLC;
/// <summary>
/// Gets the <see cref="LibVLCSharp.Shared.LibVLC"/> instance.
/// </summary>
......@@ -53,9 +54,17 @@ namespace LibVLCSharp.Forms.Sample.MediaPlayerElement
var media = new Media(LibVLC, new Uri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"));
MediaPlayer = new MediaPlayer(media) { EnableHardwareDecoding = true };
media.Dispose();
MediaPlayer.Play();
}
internal void OnDisappearing()
{
MediaPlayer.Dispose();
LibVLC.Dispose();
}
private void Set<T>(string propertyName, ref T field, T value)
{
if (field == null && value != null || field != null && !field.Equals(value))
......
......@@ -16,6 +16,12 @@ namespace LibVLCSharp.Forms.Sample
((MainViewModel)BindingContext).OnAppearing();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
((MainViewModel)BindingContext).OnDisappearing();
}
private void VideoView_MediaPlayerChanged(object sender, MediaPlayerChangedEventArgs e)
{
((MainViewModel)BindingContext).OnVideoViewInitialized();
......
......@@ -40,10 +40,14 @@ namespace LibVLCSharp.Forms.Sample
Core.Initialize();
LibVLC = new LibVLC();
var media = new Media(LibVLC, new Uri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"));
MediaPlayer = new MediaPlayer(LibVLC)
{
Media = new Media(LibVLC, new Uri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"))
Media = media
};
media.Dispose();
}
public void OnAppearing()
......@@ -52,6 +56,12 @@ namespace LibVLCSharp.Forms.Sample
Play();
}
internal void OnDisappearing()
{
MediaPlayer.Dispose();
LibVLC.Dispose();
}
public void OnVideoViewInitialized()
{
IsVideoViewInitialized = true;
......
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