【问题标题】:Using VLC control in WPF在 WPF 中使用 VLC 控件
【发布时间】:2016-02-21 04:10:32
【问题描述】:

谁能帮助我开始在 WPF 应用程序中使用 VLC 控件? 目前我做了:在我的项目中添加了引用并在 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);
     }
 }

看起来不错,但是我看不到视频...我只听到视频中的声音,控件什么也没显示...我做错了什么?

【问题讨论】:

    标签: c# wpf libvlc


    【解决方案1】:

    我在应用启动时首先做了这样的事情

    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 和 plugins 文件夹。您应该安装 VLC 2.0 或更高版本。您也可以尝试不同版本的 VLC

    【讨论】:

    • 你使用什么版本的 VLC?
    • 上帝,我发现了一个问题,这个窗口属性AllowsTransparency="True" 的问题如果我将它设置为True 视频不显示...如何使用透明背景修复它在主窗口中?
    • 1) 尝试将非透明背景设置为 vlccontrol 容器(在您的情况下为边框)
    • 2) 尝试在 vlc 设置中禁用硬件视频加速
    • 添加设置--nooverlay - 结果无,Black 容器背景 - 结果相同 - 无...我不知道该怎么做(也许你知道其他解决方案,我的意思是其他有 API 的播放器?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多