Search code examples
c#wpflibvlcvlc.dotnet

Play video from stream using Vlc.Dotnet for WPF


I want my WPF application to play video from a given stream. Tried to google, but didn't find any working example with the latest Vlc.Dotnet.Wpf version. I have installed the latest package with NuGet and here is what I have so far:

My XAML:

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

C# code:

        vlcPlayer.BeginInit();
        vlcPlayer.MediaPlayer.VlcLibDirectory = new DirectoryInfo(@"C:\Program Files (x86)\VideoLAN\VLC\");
        vlcPlayer.EndInit();

        vlcPlayer.MediaPlayer.Play(new Uri("http://79.170.191.118:1935/formula55_2/stream55_2/playlist.m3u8"));

When I run, nothing happens. However stream works fine in Vlc Player. What are my options here?

Thanks in advance.


Solution

  • This should get you started:

    public MainWindow()
    {
        InitializeComponent();
        var currentAssembly = Assembly.GetEntryAssembly();
        var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
        // Default installation path of VideoLAN.LibVLC.Windows
        var libDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
    
        this.VlcControl.SourceProvider.CreatePlayer(libDirectory/* pass your player parameters here */);
        this.VlcControl.SourceProvider.MediaPlayer.Play(new Uri("http://79.170.191.118:1935/formula55_2/stream55_2/playlist.m3u8"));
    }
    

    You will need to install https://www.nuget.org/packages/VideoLAN.LibVLC.Windows/ which is the correct way to consume libvlc libraries in .NET.

    For next time, post some logs please as otherwise it's mostly guesswork. Also check out the official samples https://github.com/ZeBobo5/Vlc.DotNet/tree/develop/src/Samples