简体   繁体   中英

How to play RTSP from VLC on C#

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.

  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.

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM