c# - 在 .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 的更新版本
帮助将受到高度评价。
解决方案
如您所料,该包不包含实际的“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;
推荐阅读
- python - GEKKO如何解决一个最优的月球软着陆问题?
- arrays - 在 C 中返回静态数组以避免内存泄漏是一种好习惯吗?
- python - 我的代码有问题吗?(蟒蛇3.72)
- scala - 内加特林表达式
- reactjs - Redux 工具包切片。如何正确添加新数组?
- python - Python库`arrow`抛出AttributeError:未知属性:“月”
- ruby - RUBY TERMINAL:为什么终端运行第一种方法而不是第二种方法?
- javascript - 有没有办法用javascript更改列表元素中的两个文本
- java - JVM 的 JSON Web 令牌支持是否包括 impl、api 和 jackson?
- docker - VMware Fusion上我的kali节点中的K8s NodePort端口无法通过