Search code examples
c#libvlclibvlcsharp

How to achieve looping playback with Libvlcsharp


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.


Solution

  • This should achieve what you're looking for

    new LibVLC("--input-repeat=2")
    

    Playlist APIs will be easier to use in LibVLC 4.