Search code examples
pythonpython-3.xvlclibvlc

How to change the volume of playback in MediaListPlayer with LibVLC?


I'm using a MediaListPlayer instance to execute a playlist. On a standard MediaPlayer instance you can use MediaPlayer.audio_set_volume(newVolume), but when I try to use the same method(audio_set_volume(newVolume)) on a MediaListPLayer instance, I get an error.: AtributeError: 'MediaListPLayer' object has no attribute 'audio_set_volume'. What is the replacement of that method for the MediaListPlayer?

This is the code:

from vlc import Instance

playlist = ['/home/user/Music/01 Signs.mp3','/home/user/Music/2U.mp3']
player = Instance()
mediaListPlayer = player.media_list_player_new()
mediaList = player.media_list_new()
for element in playlist:
    mediaList.add_media(player.media_new(element))
mediaListPlayer.set_media_list(mediaList)
mediaListPlayer.play()
mediaListPlayer.audio_set_volume(80)

Solution

  • Two years later was wondering the same thing. So here is a solution that worked for me:

    import vlc
    
    inst = vlc.Instance()
    player = inst.media_list_player_new()
    media_list = inst.media_list_new(["example.mp3"])
    player.set_media_list(media_list)
    player.play()
    
    player.get_media_player().audio_set_volume(50)
    

    MediaListPlayer.get_media_player() returns the MediaPlayer that can be used to control the volume of the MediaListPlayer during playback.