首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >目录未找到异常或FileNotFoundException在VLC.DotNet上

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

Stack Overflow用户
提问于 2015-11-18 12:26:37
回答 1查看 4.6K关注 0票数 6

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

我准确地从存储库中复制了代码,并在网上获得了NuGet,但似乎无法使它工作。我从磁盘上文件的加载中得到一个目录没有直接找到异常。

这是我的代码:

代码语言:javascript
复制
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:

( 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)在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(对象发送方,(c:\ RoutedEventArgs \ME\Visual 56中的RoutedEventArgs e)

守则如下:

代码语言:javascript
复制
 if(AssemblyName.GetAssemblyName(currentAssembly.Location).ProcessorArchitecture == ProcessorArchitecture.X86)
     e.VlcLibDirectory = new DirectoryInfo(currentDirectory);
 else
     e.VlcLibDirectory = new DirectoryInfo(currentDirectory);

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-19 16:33:06

问题肯定与您的库路径有关,尽管您必须自己调试这个问题,以便找到提供的路径和实际路径之间的确切差异。

误解可能是,哪些图书馆缺失了。您确实有Vlc.DotNet.Core.Interops.dll,但是后面缺少了nativ库。这就是为什么在尝试加载实际库时,异常在 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

ProcessorArchitecture: x86

图书馆路径:

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

图书馆路径的内容:

插件(文件夹) .keep (文件) libvlc.dll (文件) libvlccore.dll (文件)

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

代码语言:javascript
复制
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");
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33780057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档