Search code examples
pythonvlclibvlc

How to make VLC repeat the whole playlist instead of only current item using libVLC?


I'm currently using Python VLC bindings(libVLC). When initializing the Instance, I use the --input-repeat=-1 option, but this causes the playlist to only advance when I use the MediaListPlayer.next() method. I want the whole playlist to loop(not repeating each song), not only one song. Any docs on this parameters are welcome as well(I looked at the official libVLC docs, but couldn't find nothing.

Here's my code as for now:

from vlc import Instance

playlist = ['/home/username/Music/01 Signs.mp3',
 '/home/username/Music/2U.mp3',
 '/home/username/Music/now_or_never.mp3',
 '/home/username/Music/passionfruit.mp3',
 '/home/username/Music/still_got_time.mp3']

class testVLC:

    def __init__(self):
         self.list1 = playlist
         self.Player = Instance('--loop')

    def addPlaylist(self):
        self.mediaList = self.Player.media_list_new()
        for music in self.list1:
            self.mediaList.add_media(self.Player.media_new(music))
        self.listPlayer = self.Player.media_list_player_new()
        self.listPlayer.set_media_list(self.mediaList)
    def playPlaylist(self):
        self.listPlayer.play()
    def nextPlay(self):
        self.listPlayer.next()

Solution

  • You can do this by setting the playback mode:

    import vlc
    self.Player.set_playback_mode(vlc.PlaybackMode.loop)