1.NuGet上下载Vlc.DotNet.Wpf, 在https://github.com/ZeBobo5/Vlc.DotNet 上下载的源码都是最新版本的,里面有调用的示例,每个版本调用方法都不一样。 下面代码以2.2.1为例。
安装完成后,程序中会自动引用相关dll
2. 播放视频相关代码
<Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="40"/> </Grid.RowDefinitions> <wpf:VlcControl Grid.Row="0" x:Name="myControl" /> <Button x:Name="btnPlay" Width="120" Height="30" Grid.Row="1" Content="play" /> </Grid>
/// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); btnPlay.Click += BtnPlay_Click; //初始化配置,指定引用库 myControl.MediaPlayer.VlcLibDirectoryNeeded += OnVlcControlNeedsLibDirectory; myControl.MediaPlayer.EndInit(); } private void BtnPlay_Click(object sender, RoutedEventArgs e) { //myControl.MediaPlayer.Play(new Uri(AppConfig.rtspUrl)); myControl.MediaPlayer.Play(new Uri("rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov")); //throw new NotImplementedException(); } private void OnVlcControlNeedsLibDirectory(object sender, Vlc.DotNet.Forms.VlcLibDirectoryNeededEventArgs e) { var currentAssembly = Assembly.GetEntryAssembly(); var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName; if (currentDirectory == null) return; if (AssemblyName.GetAssemblyName(currentAssembly.Location).ProcessorArchitecture == ProcessorArchitecture.X86) e.VlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(currentDirectory, @"..\..\..\lib\x86\")); else e.VlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(currentDirectory, "libvlc","x64")); } }