gpt4 book ai didi

c# - VLC.DotNet 上找不到目录异常或 FileNotFoundException

转载 作者:太空狗 更新时间:2023-10-29 21:49:21 24 4
gpt4 key购买 nike

使用 Vlc.DotNet 提供的 VLC 库,我尝试在一个简单的 WPF 中实现它。

我完全复制了存储库中的代码,并在线获取了 NuGet,但似乎无法正常工作。我直接从磁盘上的文件加载中得到一个 Directory Not Found 异常。

这是我的代码:

public MainWindow()
{

InitializeComponent();
VLCControl.MediaPlayer.VlcLibDirectoryNeeded += OnVlcControlNeedsLibDirectory;
}


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

private void Button_Click(object sender, RoutedEventArgs e)
{
var d = new Microsoft.Win32.OpenFileDialog();
d.Multiselect = false;
if (d.ShowDialog() == true)
{
Uri src = new Uri(d.FileName);
VLCControl.MediaPlayer.Play(src); //Exception here
}
}

VLCControl 是 xaml 中的 VLC 控件。

通过将 VlcLibDirectory 更改为我放置库的另一个路径(例如应用程序的根目录),我得到了这个 StackTrace:

at Vlc.DotNet.Core.Interops.VlcInteropsManager..ctor(DirectoryInfo dynamicLinkLibrariesPath) at Vlc.DotNet.Core.Interops.VlcManager..ctor(DirectoryInfo dynamicLinkLibrariesPath) at Vlc.DotNet.Core.Interops.VlcManager.GetInstance(DirectoryInfo dynamicLinkLibrariesPath) at Vlc.DotNet.Core.VlcMediaPlayer..ctor(DirectoryInfo vlcLibDirectory) at Vlc.DotNet.Forms.VlcControl.EndInit() at Vlc.DotNet.Forms.VlcControl.Play(Uri uri, String[] options) at VLCTest.MainWindow.Button_Click(Object sender, RoutedEventArgs e) in c:\Users\ME\Documents\Visual Studio 2013\Projects\VLCTest\VLCTest\MainWindow.xaml.cs:ligne 56

代码变为:

 if(AssemblyName.GetAssemblyName(currentAssembly.Location).ProcessorArchitecture == ProcessorArchitecture.X86)
e.VlcLibDirectory = new DirectoryInfo(currentDirectory);
else
e.VlcLibDirectory = new DirectoryInfo(currentDirectory);

感谢您的帮助。

最佳答案

问题肯定出在您的库路径上,尽管您必须自己调试问题才能找到提供的路径与实际路径之间的确切差异。

误解可能是,缺少哪些库。您确实拥有 Vlc.DotNet.Core.Interops.dll 但您缺少背后的 nativ 库。这就是为什么在尝试加载实际库时 inside Vlc.DotNet.Core.Interops.dll 发生异常的原因。

OnVlcControlNeedsLibDirectory 函数是在 VLCControl.MediaPlayer.Play(src); 中调用的,因此 OpenFileDialog 的路径与问题无关。

我为重现/修复所采取的步骤:

  • 下载你的项目
  • 测试/调试
    • 如您所述出现异常
  • 从 Vlc.DotNet 存储库下载库
  • 将路径更改为绝对值
  • 再次测试/调试
    • 成功播放音乐文件
    • 关闭时发生另一个异常(完全不同的故事)

我的文件夹布局:

解决路径:

D:\Programmierung\VLCTest-VAlphaTesting\VLCTest-VAlphaTesting\

执行时的实际装配位置

D:\Programmierung\VLCTest-VAlphaTesting\VLCTest-VAlphaTesting\VLCTest\bin\Debug

处理器架构:x86

库路径:

D:\Programmierung\Vlc.DotNet-master\Vlc.DotNet-master\lib\x86

库路径内容:

plugins (folder)

.keep (file)

libvlc.dll (file)

libvlccore.dll (file)

出于测试目的,我对库路径进行了硬编码——您可能也想这样做

if (AssemblyName.GetAssemblyName(currentAssembly.Location).ProcessorArchitecture == ProcessorArchitecture.X86)
e.VlcLibDirectory = new DirectoryInfo(@"D:\Programmierung\Vlc.DotNet-master\Vlc.DotNet-master\lib\x86");
else
e.VlcLibDirectory = new DirectoryInfo(@"D:\Programmierung\Vlc.DotNet-master\Vlc.DotNet-master\lib\x64");

关于c# - VLC.DotNet 上找不到目录异常或 FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33780057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com