Meta.Vlc
Meta.Vlc copied to clipboard
ThreadSeparatedImage quitts showing Video when removed and added back to VisualTree
When I show the Video in a ThreadSeparatedImage I can't remove the ThreadSeparatedImage from the VisualTree, otherwise the Video isn't shown when I move it back again.
Example code (Press Clear to remove the ThreadSeparatedImage and Add to add it back again):
XAML
<Window x:Class="MetaVlcTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" Grid.Column="0">
<Button Click="Button_Click_1">Clear</Button>
<Button Click="Button_Click_2">Add</Button>
</StackPanel>
<Grid Grid.Column="1" Name="container"></Grid>
</Grid>
</Window>
Code
using System;
using System.Windows;
using Meta.Vlc.Wpf;
namespace MetaVlcTest {
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
private VlcPlayer player;
private ThreadSeparatedImage image;
public MainWindow() {
InitializeComponent();
image = new ThreadSeparatedImage();
container.Children.Add(image);
player = new VlcPlayer(true);
player.Initialize(@"..\..\LibVlc");
player.LoadMedia(new Uri("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"));
player.Play();
image.Source = player.VideoSource;
player.VideoSourceChanged += Player_VideoSourceChanged;
}
private void Player_VideoSourceChanged(object sender, VideoSourceChangedEventArgs e) {
image.Source = e.NewVideoSource;
}
private void Button_Click_1(object sender, RoutedEventArgs e) {
container.Children.Clear();
}
private void Button_Click_2(object sender, RoutedEventArgs e) {
if (container.Children.Count == 0)
container.Children.Add(image);
}
}
}
You need set the Source property again.
Setting image.Source = player.VideoSource; in Button_Click_2 after container.Children.Add(image); doesn't work for me. The only thing that worked is to replace the whole instance of the ThreadSeparatedImage.