简体   繁体   English

如何在C#上从VLC播放RTSP

[英]How to play RTSP from VLC on C#

I'm new to using the VLC on C# winforms. 我是在C#winforms上使用VLC的新手。 I installed or added a vlcControl on my C# Project using Vlc.DotNet.Forms.dll . 我使用Vlc.DotNet.Forms.dll在C#项目上安装或添加了Vlc.DotNet.Forms.dll Below is the guide on how did I install the vlcControl on my Project: 以下是有关如何在项目上安装vlcControl的指南:

https://github.com/ZeBobo5/Vlc.DotNet/wiki/Using-Vlc.DotNet-in-WinForms 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. 我还在安装的VLC播放器上测试了RTSP视频,它可以正常工作,并且具有RTSP链接。

I would like to know how can I play the RTSP on my added vlcControl? 我想知道如何在添加的vlcControl上播放RTSP? Also my RTSP has authentication. 我的RTSP也具有身份验证。

  1. Open VLC Media Player 打开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" ). 写下在日志记录窗口中显示的VLC使用的URL(类似"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. 将该URL提供给Vlc.DotNet媒体播放器,然后调用Play。
  7. Profit. 利润。

The wiki link you mentionned is outdated. 您提到的Wiki链接已过时。 This link provides more "up-to-date" info : https://github.com/ZeBobo5/Vlc.DotNet/wiki/Getting-started#vlcdotnetforms 该链接提供了更多“最新”信息: 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 您还可以查看此示例以了解其工作方式: 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. 关于身份验证,您可以使用URL中的凭据,例如rtsp://user:pass@.../ ,但这被认为是一种不好的做法,并且会导致警告。

The new way since VLC 3.0 is to use the libvlc dialog API. 自VLC 3.0以来的新方法是使用libvlc对话框API。 With Vlc.DotNet, you use that by implementing IVlcDialogManager . 通过Vlc.DotNet,可以通过实现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 您可以在此处看到示例实现(对于WPF,但相同的逻辑适用于所有平台): 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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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