Implement Looping with LibVLC

This forum is about all development around libVLC.
jules43
New Cone
New Cone
Posts: 3
Joined: 07 Apr 2016 12:07

Implement Looping with LibVLC

Postby jules43 » 07 Apr 2016 12:16

I am developing a standalone video player using LibVLC. I have a test video playing successfully and I'm now trying to implement an optional looping feature.

To do this I am attaching to the libvlc_media_player event libvlc_MediaPlayerEndReached, as expected at the end of the video I receive this event followed by libvlc_MediaPlayerVout count = 0.

At this point I want to restart the video from the beginning. My initial tests I just called libvlc from within the event handler but this sometimes caused crashes, so I'm now setting a flag for later processing.

Once the EndReached event occurs I have tried.

Code: Select all

libvlc_media_player_set_time(myVLCMediaPlayer, 0); libvlc_media_player_play(myVLCMediaPlayer);
and various other combinations of start/stop/set_time but the video does not play from the beginning.

Is there any way to do this without releasing the player and recreating it?

Thanks

Jules

jules43
New Cone
New Cone
Posts: 3
Joined: 07 Apr 2016 12:07

Re: Implement Looping with LibVLC

Postby jules43 » 07 Apr 2016 12:50

For now I am using this code to restart playback from the beginning:

Code: Select all

libvlc_media_player_set_media(mVLCMediaPlayer, mVLCMedia); libvlc_media_player_play(mVLCMediaPlayer);
The disadvantage of this appears to be that it has to re-load the cache, so it takes longer to restart when looping.

Is this the correct way of doing it?

Is there any way to get "seamless" looping without writing ones own media reader?

Thanks

Jules

User avatar
joba1
New Cone
New Cone
Posts: 6
Joined: 09 Mar 2016 00:42

Re: Implement Looping with LibVLC

Postby joba1 » 30 Apr 2016 15:25

Would also be interested in this.

Currently I may do way more than required?

Code: Select all

def __init__(self, url): ... self.tk = Tk() ... self.url = url self.instance = vlc.Instance() self.player = self.instance.media_player_new() self.event_manager = self.player.event_manager() self.event_manager.event_attach(vlc.EventType.MediaPlayerEndReached, self.onEnd) @vlc.callbackmethod def onEnd(self, event): self.tk.after_idle(self.play) def play(self): media = self.instance.media_new(self.url) self.player.set_media(media) self.player.play()
This is already simplified. Full code is here: http://banzhaf.chickenkiller.com/hg/chordsplay/

Maybe I could just reuse the media I have by setting position to 0? Nice, never tried that. Just noticed that I cant just play the media again, so I created a new one.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 9 guests