Page 1 of 1

Error detection on a Network stream.

Posted: 09 Aug 2016 23:11
by tom.abcd
I have an app that uses the LibVlc dlls and I am trying to display a RTSP network stream. I have been able to get it to work but am now trying to add the error handling.

In the VLC app if I tell it to use a network source that it can not connect to I get a Connection Failed message.
If I use the libVLC functions (see below) the events will be Opening and then Buffering and then nothing else.
So how do I detect Connection Failed with the libvlc functions?


// if you want to play from network, use libvlc_media_new_location instead
vlcMedia := libvlc_media_new_location(vlcInstance, 'rtsp://@192.168.7.22:8554/0');

// create new vlc media player
vlcMediaPlayer := libvlc_media_player_new_from_media(vlcMedia);

// now no need the vlc media, free it
libvlc_media_release(vlcMedia);

// play video in a TPanel, if not call this routine, vlc media will open a new window
libvlc_media_player_set_hwnd(vlcMediaPlayer, Pointer(pan_Video.Handle));

// play media
libvlc_media_player_play(vlcMediaPlayer);
(did not show all of the event stuff)

Thanks
Tom

Re: Error detection on a Network stream.

Posted: 26 Jan 2017 18:28
by chegarty
I've come to the exact same point. While I haven't come up with a complete solution, I do have something.

//The player must be started; the RTSP connection won't be attempted until the player_play is called!
libvlc_media_player_play(vlcMediaPlayer);

//check the media state.
libvlc_state_t state = libvlc_media_get_state(media);

//loop on whatever conditions you need, ie. wait for playing or just wait until it's not opening
while (state != libvlc_Playing)
{
Sleep(500);
state = libvlc_media_get_state(media);
//TODO: Recommend a timeout counter so you don't just spin forever

//break out if an error is encountered, such as the connection outright rejected
if (state == libvlc_Error)
break;
}

//Proceed based on the state, whether it's error or whatever