在WPF中使用VLC控制
本文关键字:VLC 控制 WPF | 更新日期: 2023-09-27 18:04:08
谁能帮助我开始使用VLC控制在WPF应用程序?在我的项目中添加了引用,并在XAML
中创建了控件。XAML:<Border Grid.Row="2"
Height="150"
Width="Auto"
Margin="10,0,10,0"
BorderThickness="1"
BorderBrush="Red" >
<pl:VlcControl x:Name="Player" />
</Border>
后台代码 public MainWindow()
{
InitializeComponent();
Player.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, @"vlslib'x86'"));
else
e.VlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(currentDirectory, @"vlslib'x64'"));
}
private void StartButton_Click(object sender, RoutedEventArgs e)
{
var d = new Microsoft.Win32.OpenFileDialog();
d.Multiselect = false;
if (d.ShowDialog() == true)
{
Uri src = new Uri(d.FileName);
Player.Visibility = System.Windows.Visibility.Visible;
Player.MediaPlayer.Play(src);
}
}
看起来不错,但是我看不到视频…我只听到视频里的声音,控制器什么也没显示…我做错了什么?
我第一次在app start
if (String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432")))
{
VlcContext.LibVlcDllsPath = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_X86;
//Set the vlc plugins directory path
VlcContext.LibVlcPluginsPath = CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_X86;
}
else
{
VlcContext.LibVlcDllsPath = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_AMD64;
//Set the vlc plugins directory path
VlcContext.LibVlcPluginsPath = CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_AMD64;
}
所以首先你应该设置dll和插件文件夹。您应该安装VLC 2.0或更高版本。您还可以尝试不同版本的VLC