[英]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:
位於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);
謝謝您的幫助。
問題肯定在於您的庫路徑,但您必須自己調試問題才能找到提供的路徑與實際路徑之間的確切差異。
誤解可能是,圖書館遺失了。 你有Vlc.DotNet.Core.Interops.dll
但你缺少后面的nativ庫。 這是什么原因,為什么發生異常里面 Vlc.DotNet.Core.Interops.dll
當它試圖加載實際庫。
OnVlcControlNeedsLibDirectory
函數在VLCControl.MediaPlayer.Play(src);
調用VLCControl.MediaPlayer.Play(src);
,所以OpenFileDialog的路徑與問題無關。
我重現/修復的步驟:
我的文件夾布局:
解決途徑:
d:\\ Programmierung \\ VLCTest-VAlphaTesting \\ VLCTest,VAlphaTesting \\
執行時的實際裝配位置
d:\\ Programmierung \\ VLCTest-VAlphaTesting \\ VLCTest-VAlphaTesting \\ VLCTest \\ BIN \\調試
ProcessorArchitecture:x86
圖書館路徑:
d:\\ Programmierung \\ Vlc.DotNet主\\ Vlc.DotNet主\\ 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");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.