Integrate VLC player in C# (WPF) project using Vlc.DotNet

前端 未结 1 372
我寻月下人不归
我寻月下人不归 2020-12-18 13:29

I want to integrate to my project a VLC player to display video cameras streams. For that, I try to use Vlc.DotNet (2.1.126 version) in my WPF project.

My tests are

相关标签:
1条回答
  • 2020-12-18 14:09

    The WPF version of the VlcControl is just a WindowsFormsHost control hosting the Windows Forms version of the VlcControl. Judging by the error message (The value of type "VlcControl" cannot be added to a collection or dictionary of type 'UIElementCollection') you're simply missing a reference to the WindowsFormsIntegration assembly, in which the WindowsFormsHost is defined (it can be found under Assemblies → Framework in the reference manager).


    Here's a fully working example of a WPF window hosting the VLC player. You need to install the Vlc.DotNet.Wpf NuGet package (and its dependencies) and reference the WindowsFormsIntegration assembly.

    MainWindow.xaml

    <Window x:Class="HelloVlc.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:vlc="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf">
        <vlc:VlcControl x:Name="vlcPlayer" />
    </Window>
    

    MainWindow.xaml.cs

    public partial class MainWindow
    {
        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"));
        }
    }
    
    0 讨论(0)
提交回复
热议问题