使用Vlc.DotNet提供的VLC库,我尝试在一个简单的WPF中实现它。
我准确地从存储库中复制了代码,并在网上获得了NuGet,但似乎无法使它工作。我从磁盘上文件的加载中得到一个目录没有直接找到异常。
这是我的代码:
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)
守则如下:
if(AssemblyName.GetAssemblyName(currentAssembly.Location).ProcessorArchitecture == ProcessorArchitecture.X86)
e.VlcLibDirectory = new DirectoryInfo(currentDirectory);
else
e.VlcLibDirectory = new DirectoryInfo(currentDirectory);谢谢你的帮助。
发布于 2015-11-19 16:33:06
问题肯定与您的库路径有关,尽管您必须自己调试这个问题,以便找到提供的路径和实际路径之间的确切差异。
误解可能是,哪些图书馆缺失了。您确实有Vlc.DotNet.Core.Interops.dll,但是后面缺少了nativ库。这就是为什么在尝试加载实际库时,异常在 Vlc.DotNet.Core.Interops.dll中发生的原因。
OnVlcControlNeedsLibDirectory函数在VLCControl.MediaPlayer.Play(src);中调用,因此来自OpenFileDialog的路径与问题无关。
我为复制/修复所采取的步骤:
我的文件夹布局:
解决途径:
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 (文件)
出于测试目的,我硬编码了库路径--您可能也想这样做。
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");https://stackoverflow.com/questions/33780057
复制相似问题