之前的文章,写了Vlc.DotNet.Wpf的标准用法,下面说说如何绑定到image控件上。
在MainWindow.xaml中添加image控件
<Image x:Name="Video1" Margin="10,10,10,10"/>
MainWindow.xaml.cs代码
//实例化播放器
sourceProvider = new VlcVideoSourceProvider(this.Dispatcher);
//初始化播放器
sourceProvider.CreatePlayer(vlcLibDirectory);
//播放流媒体
sourceProvider.MediaPlayer.Play(new Uri(@"rtmp://58.200.131.2:1935/livetv/fhzw"));
//绑定到image
this.Video1.Dispatcher.Invoke(() => {
this.Video1.SetBinding(System.Windows.Controls.Image.SourceProperty,
new Binding(nameof(VlcVideoSourceProvider.VideoSource)) { Source = sourceProvider });
});