Wpf开发VLC播放器(万能播放器)
时间:2018-05-16 10:52:15
收藏:0
阅读:4600
一、在VLC官网下载最新的VLC播放器,然后安装,安装后在安装文件目录中分别把文件VideoLAN\VLC\和VideoLAN\VLC\plugins\拷贝到项目中。
\VLC文件夹中包括\plugins文件夹、axvlc.dll、libvlc.dll、libvlccore.dll、npvlc.dll,将整个VLC文件夹复制到\bin\x86\Debug\下面;
注意:在x86平台下
二、添加引用
1.Vlc.DotNet.Core.dll
2.Vlc.DotNet.Core.Interops.dll
3.Vlc.DotNet.Forms.dll
4.Vlc.DotNet.Silverlight.dll
5.Vlc.DotNet.Wpf.dll
wpf中添加加黑的三个即可
三、前台
在XAML中添加命名空间的引用:
xmlns:local="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf"
<Grid>
<Image x:Name="img"/>
<Grid/>
四、后台
1 using Vlc.DotNet.Core; 2 using Vlc.DotNet.Core.Medias; 3 using Vlc.DotNet.Wpf; 4 5 namespace Wpf_VLCPlayer 6 { 7 /// <summary> 8 /// MainWindow.xaml 的交互逻辑 9 /// </summary> 10 public partial class MainWindow : Window 11 { 12 public MainWindow() 13 { 14 InitializeComponent(); 15 } 16 17 18 19 20 21 private void Window_Loaded(object sender, RoutedEventArgs e) 22 { 23 var appPath = AppDomain.CurrentDomain.BaseDirectory; 24 VlcContext.LibVlcDllsPath = appPath + @"VLC\"; 25 //Set the vlc plugins directory path 26 VlcContext.LibVlcPluginsPath = appPath + @"VLC\plugins\"; 27 28 //Set the startup options 29 VlcContext.StartupOptions.IgnoreConfig = true; 30 VlcContext.StartupOptions.LogOptions.LogInFile = false; 31 VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = false; 32 VlcContext.StartupOptions.LogOptions.Verbosity = VlcLogVerbosities.None; 33 34 //Initialize the VlcContext 35 VlcContext.Initialize(); 36 37 VlcControl myVlcControl = new VlcControl(); 38 // 创建绑定,绑定Image 39 Binding bing = new Binding(); 40 bing.Source = myVlcControl; 41 bing.Path = new PropertyPath("VideoSource"); 42 img.SetBinding(Image.SourceProperty, bing); 43 44 //流媒体播放 45 46 //var media = new LocationMedia("udp://@:ip:port"); 47 48 //myVlcControl.Play(media); 49 50 //本地播放 51 52 myVlcControl.Play(new PathMedia(@"E:\BirdDetect\BDRecordVideo\test11.mp4"));//添加本地视频路径 53 54 //VlcContext.CloseAll(); 55 56 57 } 58 59 60 61 62 } 63 }
评论(0)