Sử dụng thư viện VLC được cung cấp bởi Vlc.DotNet, tôi đã cố thực hiện nó trong một WPF đơn giản.Thư mục Không tìm thấy Ngoại lệ hoặc FileNotFoundException trên VLC.DotNet
Tôi đã sao chép chính xác mã từ kho lưu trữ và nhận NuGet trực tuyến, nhưng dường như không làm cho nó hoạt động. Tôi nhận được một ngoại lệ Directory Not Found ngay từ tải của tập tin trên đĩa.
Đây là mã của tôi:
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 là kiểm soát VLC trong XAML.
Bằng cách thay đổi VlcLibDirectory
với một con đường nơi tôi đặt các thư viện (ví dụ thư mục gốc của ứng dụng), tôi nhận được StackTrace này:
tại Vlc.DotNet.Core.Interops.VlcInteropsManager..ctor (DirectoryInfo dynamicLinkLibrariesPath) tại Vlc.DotNet.Core.Interops.VlcManager..ctor (DirectoryInfo dynamicLinkLibrariesPath) tại Vlc.DotNet.Core.Interops.VlcManager.GetInstance (DirectoryInfo dynamicLinkLibrariesPath) tại Vlc.DotNet.Core.VlcMediaPlayer..ctor (DirectoryInfo vlcLibDirectory) tại Vlc.DotNet.Forms.VlcControl.EndInit() tại Vl c.DotNet.Forms.VlcControl.Play (Uri uri, String [] tùy chọn) tại VLCTest.MainWindow.Button_Click (đối tượng người gửi, RoutedEventArgs e) trong c: \ Users \ ME \ Documents \ Visual Studio 2013 \ Projects \ VLCTest \ VLCTest \ MainWindow.xaml.cs: ligne 56
mã này trở thành:
if(AssemblyName.GetAssemblyName(currentAssembly.Location).ProcessorArchitecture == ProcessorArchitecture.X86)
e.VlcLibDirectory = new DirectoryInfo(currentDirectory);
else
e.VlcLibDirectory = new DirectoryInfo(currentDirectory);
Cảm ơn bạn đã giúp đỡ của bạn.
Bạn bắt đầu từ VS? Đi từ currentDirectory là có một thư mục x86 hoặc x64 (".. \ .. \ .. \ lib \ x86 \") – Jehof
@Default Chắc chắn, vì nó là một đường dẫn từ tệp bạn nhận được từ FileDialog. @ Jehof, Ngoại lệ xảy ra khi tệp tải, không phải chính trình phát. Người chơi thực sự có được con đường tốt cho 'VlcLibDirectory' (tôi nghĩ vậy?), Nhờ vào thư viện – JoJoeTheBear
@Jehof Xin lỗi vì bình luận đôi. Có trong VS. – JoJoeTheBear