Page 1 of 1

Replay "ended" media

Posted: 28 Mar 2019 01:29
by liammartens
I am probably doing something wrong but I will ask the question anyways. I am trying to repeat something after it ends. The setup I have now is something like this:

Code: Select all

libvlc_media_player_t* player = libvlc_media_player_new(vlc_instance); libvlc_event_manager_t* evt_mgr = libvlc_media_player_event_manager(player); void on_media_end(onst libvlc_event_t* evt, void* user_data) { libvlc_media_player_set_position(player, 0.0f); libvlc_media_player_play(player); } libvlc_event_attach(evt_mgr, libvlc_MediaPlayerEndReached, on_media_end); libvlc_media_t* media = libvlc_media_new_location(vlc_instance, "path"); libvlc_media_player_set_media(player, media); libvlc_media_player_play(this->m_player);
The MediaEnd event is fired correctly when the video ends, no issues there but I can't seem to get it to seek back to the start and play the video again for some reason and I am not sure what is going wrong here. What am I missing?

Re: Replay "ended" media

Posted: 28 Mar 2019 08:00
by Jean-Baptiste Kempf
As explained, you should not call libvlc_ from within libvlc_ callbacks.

Re: Replay "ended" media

Posted: 28 Mar 2019 08:22
by liammartens
Ok noted, but it seems that even when I move the function calls to a detached thread it still does not seek back and replay.
It does work when I call media_player stop on it first but then I get the initial black screen which I don't want I would need it to keep the media so it can immediately restart on first frame.

Code: Select all

void on_media_end(onst libvlc_event_t* evt, void* user_data) { auto replay [player]() { libvlc_media_player_set_position(player, 0.0f); libvlc_media_player_play(player); } thread t(replay); t.detach(); }

Re: Replay "ended" media

Posted: 28 Mar 2019 10:54
by sherington
Call libvlc_media_player_stop before you call libvlc_media_player_play.

Re: Replay "ended" media

Posted: 28 Mar 2019 11:14
by liammartens
Yes as I said in my reply, it does work when I call stop first but I need to prevent the black frame flash before the media starts playing so I need to hold the first frame as it starts and not completely stop it.