Vlc.DotNet在winform中的使用

试了很多次,终于调通了。可以用作万能视频播放器了。

vlc.dotnet有4个包,网址是http://www.nuget.org/packages/Vlc.DotNet.Core/  

Vlc.DotNet.Core.Interops 

Vlc.DotNet.Core 

Vlc.DotNet.Forms 

Vlc.DotNet.Wpf 

后面的依赖前面的各项。直接使用vs2015, 打开NuGet包管理器,搜索vlc就可以找到。然后依次安装。
或者直接输入命令 install-package vlc.dotnet.forms 他会自动安装前两项,注意不区分大小写。

装好之后,工具箱添加项,找到vlc.dotnet.forms,添加进去可以使用vlcControls. 

调用vlcControls之后,注意要设置dll目录,或者直接拷贝源码中的查找dll函数。如下:

        private void vlcControl1_VlcLibDirectoryNeeded(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(Path.Combine(currentDirectory, @"lib\x86\"));
            else
                e.VlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, @"lib\x64\"));

            if (!e.VlcLibDirectory.Exists)
            {
                var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
                folderBrowserDialog.Description = "Select Vlc libraries folder.";
                folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
                folderBrowserDialog.ShowNewFolderButton = true;
                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    e.VlcLibDirectory = new DirectoryInfo(folderBrowserDialog.SelectedPath);
                }
            }
        }

添加个button按钮,写入播放命令就可以播放了。比如如下:我调试很多次主要是,一直用的源码中的dll搞不定,1是可能x86,x64自己绕死了。2是可能那个源码中dll用了保护,不可引用,用了总是内存报错。很是抓狂。希望后面的人不要走我的老路了。


//vlcControl1.Play(new Uri("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi"));
vlcControl1.Play(new FileInfo(@"Bear.wmv"));


话说这个编辑器真是让我吐血。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值