Replay "ended" media

This forum is about all development around libVLC.
liammartens
New Cone
New Cone
Posts: 5
Joined: 17 Mar 2019 23:31
Operating System: Linux
Contact:

Replay "ended" media

Postby liammartens » 28 Mar 2019 01:29

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?

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: Replay "ended" media

Postby Jean-Baptiste Kempf » 28 Mar 2019 08:00

As explained, you should not call libvlc_ from within libvlc_ callbacks.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

liammartens
New Cone
New Cone
Posts: 5
Joined: 17 Mar 2019 23:31
Operating System: Linux
Contact:

Re: Replay "ended" media

Postby liammartens » 28 Mar 2019 08:22

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

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: Replay "ended" media

Postby sherington » 28 Mar 2019 10:54

Call libvlc_media_player_stop before you call libvlc_media_player_play.

liammartens
New Cone
New Cone
Posts: 5
Joined: 17 Mar 2019 23:31
Operating System: Linux
Contact:

Re: Replay "ended" media

Postby liammartens » 28 Mar 2019 11:14

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.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 14 guests