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

JoJ*_*ear 6 c# wpf exception vlc

使用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
        }
    }
Run Code Online (Sandbox Code Playgroud)

VLCControl是xaml中的VLC控件.

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

位于Vlc.DotNet.Core.Interops.VlcManager.ctor(DirectoryInfo dynamicLinkLibrariesPath)的Vlc.DotNet.Core.Interops.VlcInteropsManager..ctor(DirectoryInfo dynamicLinkLibrariesPath)位于Vlc.DotNet.Core.Interops.VlcManager.GetInstance(DirectoryInfo dynamicLinkLibrariesPath)在Vlc.DotNet.Core.VlcMediaPlayer..ctor(DirectoryInfo vlcLibDirectory)Vlc.DotNet.Forms.VlcControl.EndInit()at Vlc.DotNet.Forms.VlcControl.Play(Uri uri,String [] options)at VLCTest.MainWindow .Button_Click(Object sender,RoutedEventArgs e)位于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);
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助.

gre*_*k40 3

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

误解可能是缺少哪些库。你确实有,Vlc.DotNet.Core.Interops.dll但你缺少后面的本机库。这就是当它尝试加载实际库时内部 发生异常的原因。Vlc.DotNet.Core.Interops.dll

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

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

  • 下载了您的项目
  • 已测试/调试
    • 正如您所描述的,发生了异常
  • 从 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

库路径内容:

插件(文件夹)

.keep(文件)

libvlc.dll(文件)

libvlccore.dll(文件)

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

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");
Run Code Online (Sandbox Code Playgroud)