代码之家  ›  专栏  ›  技术社区  ›  Mikael

如何使用LibVLC更改MediaListPlayer中的播放音量?

  •  2
  • Mikael  · 技术社区  · 7 年前

    MediaListPlayer 实例来执行播放列表。在标准上 MediaPlayer 您可以使用的实例 MediaPlayer.audio_set_volume(newVolume) ,但当我尝试使用相同的方法时( audio_set_volume(newVolume) MediaListPLayer 例如,我得到一个错误: AtributeError: 'MediaListPLayer' object has no attribute 'audio_set_volume' MediaListPlayer ?

    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)
    
    2 回复  |  直到 7 年前
        1
  •  5
  •   Maybe    5 年前

    两年后,我也在想同样的事情。这是一个对我有效的解决方案:

    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\u media\u player()返回可用于在播放期间控制MediaListPlayer音量的MediaPlayer。

        2
  •  0
  •   Rolf of Saxony    7 年前

    正如我在评论中所说,这看起来确实像是疏忽。
    然而,我已经设法通过黑客攻击sub_播放器来设置初始音量,但一旦设置好了,您调用列表播放器,我就没有找到调整它的方法。

    import vlc
    import time
    playlist=['/home/rolf/vp1.mp3','/home/rolf/vp.mp3']
    inst = vlc.Instance()
    sub_player = inst.media_player_new()
    player = inst.media_list_player_new()
    mediaList = inst.media_list_new(playlist)
    player.set_media_list(mediaList)
    volume = 60
    sub_player.audio_set_volume(volume)
    sub_player.play()
    playing = set([1,2,3,4])
    player.play()
    while player.get_state() in playing:
        time.sleep(1)
    

    https://forum.videolan.org/viewtopic.php?f=32&t=139505 因此,对这些事情有更深入了解的人可能会提供更好的解决方案。如果我得到答案,我会把它贴在这里。