Looping playback

This forum is about all development around libVLC.
fractal-1
New Cone
New Cone
Posts: 9
Joined: 15 Sep 2024 02:34

Looping playback

Postby fractal-1 » 08 Oct 2024 03:10

According to this https://github.com/videolan/libvlcsharp ... _I_do_X.md to achieve looping playback we should use new LibVLC("--input-repeat=2")

But what if we're trying to deactivate the looping playback while the video is playing? Is there a way to pass a parameter to LibVLC to stop looping a video?

Rémi Denis-Courmont
Developer
Developer
Posts: 15271
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Looping playback

Postby Rémi Denis-Courmont » 08 Oct 2024 03:21

Using LibVLC options is not supported in any way. I believe the documentation for libvlc_new() is abundantly clear.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

mfkl
Developer
Developer
Posts: 746
Joined: 13 Jun 2017 10:41

Re: Looping playback

Postby mfkl » 08 Oct 2024 06:32

Using LibVLC options is not supported in any way. I believe the documentation for libvlc_new() is abundantly clear.
And yet, it works, likely supported during major version timelines and it's the only way to do many things until LibVLC offers a proper C API for these things.
But what if we're trying to deactivate the looping playback while the video is playing? Is there a way to pass a parameter to LibVLC to stop looping a video?
Using this approach, I don't think this is possible.

Another way to achieve looping which would give you control to disable looping, is to use the mediaplayer.EndReached event to kick off a new playback to loop (and not when you want to stop).

Yet another way is to get the video length, subscribe to the position or time changed event and set position to 0 just before the playback finishes.
https://mfkl.github.io

fractal-1
New Cone
New Cone
Posts: 9
Joined: 15 Sep 2024 02:34

Re: Looping playback

Postby fractal-1 » 08 Oct 2024 14:36

Using LibVLC options is not supported in any way. I believe the documentation for libvlc_new() is abundantly clear.
And yet, it works, likely supported during major version timelines and it's the only way to do many things until LibVLC offers a proper C API for these things.
But what if we're trying to deactivate the looping playback while the video is playing? Is there a way to pass a parameter to LibVLC to stop looping a video?
Using this approach, I don't think this is possible.

Another way to achieve looping which would give you control to disable looping, is to use the mediaplayer.EndReached event to kick off a new playback to loop (and not when you want to stop).
Thanks for reply. But I still need some help. I'm making an app in C# using WinForms. I'm trying to implement 2 modes that can be switched anytime: 1. each video is played in a loop until the user switches to the next video and 2. each video is played once and then the next one is loaded (kinda like a slideshow).

I made the mode 1, now I'm trying to made mode 2. Apparently we can't use mediaPlayer.Stop() directly at MediaPlayer_EndReached because of a well known bug. Here is the code to stop the playback:

Code: Select all

public void MediaPlayer_EndReached(object sender, EventArgs args) { ThreadPool.QueueUserWorkItem(_ => mediaPlayer.Stop()); }
Now, how do I call the custom function to load the next video PlayNextFile() from MediaPlayer_EndReached? I get this runtime error:

Code: Select all

System.InvalidOperationException HResult=0x80131509 Message=Cross-thread operation not valid: Control 'MainForm' accessed from a thread other than the thread it was created on.
Basically I'm trying to make VLC to play the next video (from a string List) immediately after the current video ended.
Yet another way is to get the video length, subscribe to the position or time changed event and set position to 0 just before the playback finishes.
Something like this?

Code: Select all

private void MediaPlayer_TimeChanged(object sender, MediaPlayerTimeChangedEventArgs e) { if (e.Time + 150 >= media.Duration) { mediaPlayer.Position = 0; } }
What would you suggest? How many times per second is TimeChanged triggered? What is the most reliable way to get the moment a video ended?

mfkl
Developer
Developer
Posts: 746
Joined: 13 Jun 2017 10:41

Re: Looping playback

Postby mfkl » 09 Oct 2024 13:38

When the end is reached, the player is already stopped, so no point in stopping it again. Just play the next media.
https://mfkl.github.io

fractal-1
New Cone
New Cone
Posts: 9
Joined: 15 Sep 2024 02:34

Re: Looping playback

Postby fractal-1 » 09 Oct 2024 17:03

When the end is reached, the player is already stopped, so no point in stopping it again. Just play the next media.
Thanks. But is when is the last moment when the player sends the playing time (how many ms before end)?

mfkl
Developer
Developer
Posts: 746
Joined: 13 Jun 2017 10:41

Re: Looping playback

Postby mfkl » 14 Oct 2024 06:13

That's unknown.
https://mfkl.github.io


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 6 guests