VLC.DotNet 上的目录未找到异常或 FileNotFoundException

Directory Not Found Exception or FileNotFoundException on VLC.DotNet

使用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 但你缺少背后的原生库。这就是为什么在尝试加载实际库时 inside Vlc.DotNet.Core.Interops.dll 发生异常的原因。

VLCControl.MediaPlayer.Play(src);内部调用了OnVlcControlNeedsLibDirectory函数,所以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");