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?