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"));


話說這個編輯器真是讓我吐血。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章