Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play RTSP from VLC on C#

Tags:

c#

vlc

vlc.dotnet

I'm new to using the VLC on C# winforms. I installed or added a vlcControl on my C# Project using Vlc.DotNet.Forms.dll. Below is the guide on how did I install the vlcControl on my Project:

https://github.com/ZeBobo5/Vlc.DotNet/wiki/Using-Vlc.DotNet-in-WinForms

I also tested my RTSP video on my installed VLC player and it's working and I have the RTSP link.

I would like to know how can I play the RTSP on my added vlcControl? Also my RTSP has authentication.

like image 765
Richard Avatar asked Oct 21 '25 17:10

Richard


2 Answers

The wiki link you mentionned is outdated. This link provides more "up-to-date" info : https://github.com/ZeBobo5/Vlc.DotNet/wiki/Getting-started#vlcdotnetforms

You can also look at this sample to see how it works : https://github.com/ZeBobo5/Vlc.DotNet/tree/develop/src/Samples/Samples.WinForms.Minimal

Regarding authentication, you could use the credentials in the URL, like rtsp://user:pass@.../, but this is considered a bad practice and will result in a warning.

The new way since VLC 3.0 is to use the libvlc dialog API. With Vlc.DotNet, you use that by implementing IVlcDialogManager. You can see an example implementation here (for WPF, but the same logic applies to all platforms): https://github.com/ZeBobo5/Vlc.DotNet/blob/develop/src/Samples/Samples.Wpf.Dialogs/MetroDialogManager.cs

For example, you could do something like:

    public class MyDialogManager : IVlcDialogManager
    {
        public async Task<LoginResult> DisplayLoginAsync(IntPtr userdata, IntPtr dialogId, string title, string text, string username, bool askstore,
            CancellationToken cancellationToken)
        {
            return new LoginResult
            {
                Username = "username",
                Password = "password",
                StoreCredentials = false
            };
        }

        public Task DisplayErrorAsync(IntPtr userdata, string title, string text)
        {
            // You could log errors here, or show them to the user
            return Task.CompletedTask;
        }

        public async Task DisplayProgressAsync(IntPtr userdata, IntPtr dialogId, string title, string text, bool indeterminate, float position,
            string cancelButton, CancellationToken cancellationToken)
        {
            return Task.CompletedTask;
        }

        public void UpdateProgress(IntPtr userdata, IntPtr dialogId, float position, string text)
        {
        }

        public async Task<QuestionAction?> DisplayQuestionAsync(IntPtr userdata, IntPtr dialogId, string title, string text, DialogQuestionType questionType,
            string cancelButton, string action1Button, string action2Button, CancellationToken cancellationToken)
        {
            return Task.FromResult<QuestionAction?>(null);
        }
    }

Use it like this:

mediaPlayer.Dialogs.UseDialogManager(new MyDialogManager(this));
like image 93
cube45 Avatar answered Oct 23 '25 07:10

cube45


  1. Open VLC Media Player
  2. Turn on Debug logging
  3. Play your stream
  4. Enter credentials
  5. Write down the URL used by VLC displayed in the logging window (something like "rtsp://192.168.1.62:554/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif&user=admin&password=xxx").
  6. Give that URL to the Vlc.DotNet mediaplayer and call Play.
  7. Profit.
like image 32
mfkl Avatar answered Oct 23 '25 06:10

mfkl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!