Commit 486cc46b authored by Martin Finkel's avatar Martin Finkel

Samples: Dispose resources in the WPF sample

parent c6b0c74b
......@@ -20,6 +20,14 @@ namespace LibVLCSharp.WPF.Sample
parent.VideoView.Loaded += VideoView_Loaded;
PlayButton.Click += PlayButton_Click;
StopButton.Click += StopButton_Click;
Unloaded += Controls_Unloaded;
}
private void Controls_Unloaded(object sender, RoutedEventArgs e)
{
_mediaPlayer.Stop();
_mediaPlayer.Dispose();
_libVLC.Dispose();
}
private void VideoView_Loaded(object sender, RoutedEventArgs e)
......@@ -42,8 +50,8 @@ namespace LibVLCSharp.WPF.Sample
{
if (!parent.VideoView.MediaPlayer.IsPlaying)
{
var uri = new Uri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4");
parent.VideoView.MediaPlayer.Play(new Media(_libVLC, uri));
using (var media = new Media(_libVLC, new Uri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")))
parent.VideoView.MediaPlayer.Play(media);
}
}
}
......
......@@ -31,6 +31,14 @@ namespace LibVLCSharp.WPF.Sample
// we need the VideoView to be fully loaded before setting a MediaPlayer on it.
VideoView.Loaded += (sender, e) => VideoView.MediaPlayer = _mediaPlayer;
Unloaded += Example2_Unloaded;
}
private void Example2_Unloaded(object sender, RoutedEventArgs e)
{
_mediaPlayer.Stop();
_mediaPlayer.Dispose();
_libVLC.Dispose();
}
void StopButton_Click(object sender, RoutedEventArgs e)
......@@ -45,8 +53,8 @@ namespace LibVLCSharp.WPF.Sample
{
if (!VideoView.MediaPlayer.IsPlaying)
{
VideoView.MediaPlayer.Play(new Media(_libVLC,
new Uri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")));
using(var media = new Media(_libVLC, new Uri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")))
VideoView.MediaPlayer.Play(media);
}
}
......
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