【问题标题】:Problem adding vlc to my WPF project using Vlc.DotNet使用 Vlc.DotNet 将 vlc 添加到我的 WPF 项目时出现问题
【发布时间】:2020-08-21 07:27:25
【问题描述】:

我想将 vlc 播放器集成到我的项目中,以显示 IP 摄像机的流。我正在关注这个Integrate VLC player in C# (WPF) project using Vlc.DotNet 进行演示。这是我的 C# 代码:

    using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Vlc.DotNet.Wpf;

namespace RTSPyVLC
{
    /// <summary>
    /// Lógica de interacción para MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            vlcPlayer.MediaPlayer.VlcLibDirectory =
                //replace this path with an appropriate one
                new DirectoryInfo(@"c:\Program Files (x86)\VideoLAN\VLC\");
            vlcPlayer.MediaPlayer.EndInit();
            vlcPlayer.MediaPlayer.Play(new Uri("http://download.blender.org/peach/" +
                "bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi"));
        }
    }
}

我也这样做,但出现错误:VlcControl 不包含“MediaPlayer”的定义... 确实如此,VlcControl 类不包含它。问题是我是否添加了错误的包(Vlc.DotNet.wpf by ZeBobo5 添加了 NuGet)或者还有另一种方法可以将 vlc 播放器与这个库集成。如果您知道示例或指南,那就太好了。

非常感谢。

【问题讨论】:

  • 你能显示你的 wpf 代码吗?
  • 我已经解决了这个问题,谢谢。我想知道的是如何减少缓冲区以减少延迟。

标签: c# wpf vlc vlc.dotnet


【解决方案1】:

你有一个帮助WIKI for VLC,在网页底部你有关于 wpf 的所有信息和一个示例。

在 wpf 中:

<Vlc:VlcControl xmlns:Vlc="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf" x:Name="MyControl" />

在您的视图构造函数中,在调用 InitializeComponent() 之后

  var vlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));

        var options = new string[]
        {
            // VLC options can be given here. Please refer to the VLC command line documentation.
        };

        this.MyControl.SourceProvider.CreatePlayer(vlcLibDirectory, options);

        // Load libvlc libraries and initializes stuff. It is important that the options (if you want to pass any) and lib directory are given before calling this method.
        this.MyControl.SourceProvider.MediaPlayer.Play("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_h264.mov");

【讨论】:

  • 您提到的 wiki 链接是一个很好的起点。但是,出于性能原因,我通常建议不要使用 Wpf 控件,而只包装 WinForms 控件(请参阅自述文件)。另一个提示:现在有一个 NuGet 包可以安装和重新分发 Windows 的 libvlc(请参阅 wiki)
  • 谢谢,成功了!我必须将 vlc 插件添加到存储库中,我完全忘记了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-17
  • 1970-01-01
  • 1970-01-01
  • 2015-12-15
  • 1970-01-01
相关资源
最近更新 更多