首页 > 解决方案 > 在 .Net Core 的 WInform 应用程序中嵌入 VLC 播放器。Core.Intialize() 给出异常

问题描述

我正在尝试在 .net core 3.1 框架上的 Winform 应用程序中嵌入 VLc。安装的软件包是 ** LibVLCSharp 3.6.1 LibVLCSharp.WinForms 3.6.1 **

private void PlayerForm_Load(object sender, EventArgs e)
        {
            var url = typeof(LibVLC).Assembly.Location;
            Core.Initialize();
            using(var libvlc = new LibVLC())
                using (var mediaPlayer = new MediaPlayer(libvlc))
            {
                var uri = new Uri("C:\\Active Projects\\ScreenPlayerWeb\\ScreenPlayerWeb\\wwwroot\\Videos\\VID_20190621_112556.3gp");
                using var media = new Media(libvlc, uri);
                mediaPlayer.Fullscreen = true;
                mediaPlayer.Play();
            }
        }

Core.Initialize() 给出异常

** LibVLCSharp.Shared.VLCException: '未能加载所需的本机库。您是否从 nuget 为您的目标平台安装了最新的 LibVLC 包?搜索路径包括 C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\libvlc\win-x64\libvlc.dll,C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3 .1\libvlc\win-x64\libvlccore.dll;C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\libvlc\win-x64\libvlc.dll,C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\ libvlc\win-x64\libvlccore.dll;C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\libvlc.dll,'

**

它在我的 devug/netcore3.1 文件夹中搜索错误文件,没有 libvlc.dll 文件……可用的文件有 libvlcsharp.dll、libvlcsharp.winforms.dll 和 vlc.dotnet.core.dll。

有关于堆栈溢出的答案,但其中大多数已经超过 5 年,因此不能参考 LIbVlc 和 .Net 的更新版本

帮助将受到高度评价。

标签: c#.netwinformslibvlc

解决方案


如您所料,该包不包含实际的“libvlc”,它是 LibVLCSharp 中唯一的初始化代码。确保您VideoLAN.LibVLC.[YourPlatform]在目标项目中安装了该软件包。或者手动下载并指向文件夹:

Core.Initialize(@"C:\yourpath\libvlc\win-x64");
var libvlc = new LibVLC();
// Make VideoView control
VideoView vv = new VideoView();
vv.MediaPlayer = new MediaPlayer(libvlc);
vv.Dock = DockStyle.Fill; 
// Add it to the form
Controls.Add(vv);

var uri = new Uri(@"C:\Video.mp4");
// Use command line options as Options for media playback (https://wiki.videolan.org/VLC_command-line_help/)
var media = new Media(libvlc, uri, ":input-repeat=65535");
vv.MediaPlayer.Play(media);

//Set fullscreen
this.FormBorderStyle = FormBorderStyle.None;
this.Size = Screen.PrimaryScreen.Bounds.Size;
this.Location = Screen.PrimaryScreen.Bounds.Location;

推荐阅读