1

我想将 vlc 播放器集成到我的项目中,以显示 IP 摄像机的流。我正在使用 Vlc.DotNet 在 C# (WPF) 项目中关注这个 Integrate VLC player进行演示。这是我的 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 类不包含它。问题是我是否添加了错误的包(ZeBobo5 的 Vlc.DotNet.wpf 添加了 NuGet)或者还有另一种方法可以将 vlc 播放器与这个库集成。如果您知道示例或指南,那将是非常棒的。

十分感谢。

4

1 回答 1

1

你有一个VLC 的帮助 WIKI,在网页的底部你有关于 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");
于 2020-05-06T11:54:14.413 回答