Reputation: 53
I have libvlcsharp working for both my windows and android project. Its very nice and easy to use! But I can't find any way to make the playback automatically loop
I've tried using the mediaplayer event handlers to restart playback and passing options into the media after creation, but nothing seems to work.
I tried:
loopSong = new Media(VLCMediaPlayer.LibVLC, xmlLoader.GetResourceStream(loopFileName));
loopSong.AddOption(":no-video");
loopSong.AddOption(":input-repeat");
and
static VLCMediaPlayer()
{
Core.Initialize();
LibVLC = new LibVLC();
MediaPlayer = new MediaPlayer(LibVLC);
MediaPlayer.EndReached += MediaPlayer_EndReached;
}
private static void MediaPlayer_EndReached(object sender, EventArgs e)
{
MediaPlayer.Stop();
MediaPlayer.Play();
}
Playback simply ceases. The events are called but MediaPlayer.WillPlay is false and calling Play does nothing.
Upvotes: 5
Views: 9898
Reputation: 2159
This should achieve what you're looking for
new LibVLC("--input-repeat=2")
Playlist APIs will be easier to use in LibVLC 4.
Upvotes: 6
Reputation: 3979
This is a famously known bug (by us at least) that happens when you call libvlc from a libvlc callback. Since Libvlc calls events from the thread that plays the video, when you call Stop(), you're waiting synchronously for that thread to finish, causing the deadlock.
Here is the workaround I proposed for Vlc.DotNet : https://github.com/ZeBobo5/Vlc.DotNet/wiki/Vlc.DotNet-freezes-(don't-call-Vlc.DotNet-from-a-Vlc.DotNet-callback)
public void MediaEndReached(object sender, EventArgs args)
{
ThreadPool.QueueUserWorkItem(() => this.MediaPlayer.Stop());
}
This will probably be solved in a future version of LibVLCSharp, see https://code.videolan.org/videolan/LibVLCSharp/issues/122
Upvotes: 8