Detect if RTSP stream is up with LibVLCSharp

1.7k views Asked by At

I have a device that streams a RTSP video, I need to show it using the VLC (LibVLCSharp) media player.

    LibVLC libVLC = new LibVLC();
    MediaPlayer mediaPlayer = new MediaPlayer(libVLC);
    
    Media media = new Media(m_libVLC, "rtsp://192.168.0.10/vid1.sdp", FromType.FromLocation);
    mediaPlayer.Play(media);

I have two problems:

  1. Sometimes the media player starts playing when the device hasn't stared streaming yet.
  2. The device stops streaming and resumes after several minutes. In both cases, the video isn't displayed.

Are there any VLC configurations for "auto - play" stream whenever it is ready? Can I know whenever the stream is ready?

I would really appreciate any suggestions.

1

There are 1 answers

3
cube45 On

You might use a .net library like RtspClientSharp to make request to the device and see if it replies.

If you don't want to bother with an additional library, you might as well open a TCP socket on the rtsp port and see if the connection succeeds.