使用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) 在Vlc.DotNet.Core.Interops.VlcManager..ctor(DirectoryInfo dynamicLinkLibrariesPath) 在Vlc.DotNet.Core.Interops.VlcManager.GetInstance(DirectoryInfo dynamicLinkLibrariesPath) 在Vlc.DotNet.Core.VlcMediaPlayer..ctor(DirectoryInfo vlcLibDirectory) 在Vlc.DotNet.Forms.VlcControl.EndInit() 在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);
感谢您的帮助。
答案 0 :(得分:3)
问题肯定在于你的库路径,尽管你必须自己调试问题才能找到提供的路径和实际路径之间的确切差异。
误解可能是,哪些图书馆遗失了。您确实拥有Vlc.DotNet.Core.Interops.dll
,但您遗漏了后面的nativ库。这就是为什么在尝试加载实际库时,在 Vlc.DotNet.Core.Interops.dll
内发生异常的原因。
OnVlcControlNeedsLibDirectory
函数在VLCControl.MediaPlayer.Play(src);
内调用,因此OpenFileDialog中的Path与问题无关。
我重现/修复的步骤:
我的文件夹布局:
解决方案路径:
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");