Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directory Not Found Exception or FileNotFoundException on VLC.DotNet

Using the VLC library provided by Vlc.DotNet, I have tried to implement it in a simple WPF.

I copied exactly the code from the repository, and got the NuGet online, but can't seem to make it work. I get a Directory Not Found exception straight from the load of the file on the disk.

Here is my code:

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 being the VLC control in the xaml.

By changing the VlcLibDirectory with another path where I put the libraries (for example the root of application), I get this 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

The code becomes :

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

Thank you for your help.

like image 407
JoJoeTheBear Avatar asked Nov 18 '15 12:11

JoJoeTheBear


1 Answers

The problem is definitely with your library path, though you have to debug the problem yourself in order to find the exact discrepancy between provided path and actual path.

The misunderstanding may be, which libraries are missing. You do have the Vlc.DotNet.Core.Interops.dll but your are missing the nativ libraries behind. This is the reason, why the exception occurs inside Vlc.DotNet.Core.Interops.dll when it tries to load the actual libraries.

The OnVlcControlNeedsLibDirectory function is called inside VLCControl.MediaPlayer.Play(src);, so the Path from OpenFileDialog has nothing to do with the problem.

Steps I taken to reproduce / fix:

  • Downloaded your project
  • Tested / Debugged
    • Exception occurred as you describe
  • Downloaded the libraries from Vlc.DotNet repository
  • Changed the paths to absolute values
  • Tested / Debugged again
    • Successfully played a music file
    • Another exception occured on closing (different story alltogether)

My folder layout:

Solution path:

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

Actual Assembly location on execute

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

ProcessorArchitecture: x86

Library Path:

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

Contents of library path:

plugins (folder)

.keep (file)

libvlc.dll (file)

libvlccore.dll (file)

For testing purposes I hardcoded the library path - you may want to do that as well

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");
like image 113
grek40 Avatar answered Nov 15 '22 14:11

grek40