在WPF中,使用Vlc.DotNet.Wpf时,我们可以使用绑定Image控件源的办法实现媒体的播放。
xaml:
……
<Image x:Name="imageMonitor" Margin="5" />
……
代码:
……
VlcVideoSourceProvider sourceProvider = new VlcVideoSourceProvider(this.Dispatcher);
var vlcLibDirectory = new DirectoryInfo(vlcPath); //VLC目录
sourceProvider.CreatePlayer(vlcLibDirectory);
//绑定到image
this.imageMonitor.Dispatcher.Invoke(() =>
{
this.imageMonitor.SetBinding(System.Windows.Controls.Image.SourceProperty,
new Binding(nameof(VlcVideoSourceProvider.VideoSource)) { Source = sourceProvider });
});
sourceProvider.MediaPlayer.Play(new Uri("screen://"), playOpti