You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VLC Media Player停止时调节音量无效问题求助

VLC播放器音量设置异常问题

我编写了一个带有播放、停止按钮及音量滑块的VLC Media Player小Demo。播放器处于播放状态时,音量滑块可正常调节音量;但处于停止状态下调整滑块位置后,需点击两次播放按钮才能让音量按新设置生效,仅点击一次播放时仍保持原音量设置。

以下是相关代码:

import vlc
from tkinter import *
from tkinter import ttk
        
volume_ini=50
url='http://direct.fipradio.fr/live/fip-midfi.aac'

instance=vlc.Instance('--input-repeat=-1','--fullscreen')
player=instance.media_player_new()
media=instance.media_new(url)
player.set_media(media)
            
root=Tk()
window_height=240
window_width=320
screen_width=root.winfo_screenwidth()
screen_height=root.winfo_screenheight()
x_cordinate = int((screen_width/2) - (window_width/2))
y_cordinate = int((screen_height/2) - (window_height/2))
root.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))

v1=DoubleVar()


def st():
    player.stop()
 
def pl():
    global player
    global volume_ini
    player.audio_set_volume(volume_ini)
    player.play()

class BarVolume(ttk.Scale):
   def __init__(self, master):
        global v1
        global volume_ini
        ttk.Scale.__init__(self,master,
        variable=v1,from_=0,to=100,orient=HORIZONTAL,length=80)
        self.volume=volume_ini
        self.bind("<ButtonRelease-1>", self.updateValue)
        self.set(volume_ini)
       
   def updateValue(self, event):
       global volume_ini 
       global v1
       global player
       volume_ini=int(v1.get())
       self.volume=volume_ini
       labelText.set(str(volume_ini))
       player.audio_set_volume(self.volume)


 
content1 = ttk.Frame(root)
content1.grid(column=0, row=0)

led_1=ttk.Button(content1, text='play',command=lambda:pl(),width=20)
led_1.grid(column=0, row=0)
led_2=ttk.Button(content1, text='stop',command=lambda:st(),width=10)
led_2.grid(column=0, row=1)
labelText = StringVar()

lbl=ttk.Label(content1,textvariable=labelText,width=20)
lbl.grid(column=0, row=3)
echelle=BarVolume(content1)
echelle.grid(column=0, row=4)


root.mainloop()

player.stop()

我尝试过调整全局变量与局部变量,也将整个窗口用类进行封装,但问题仍未解决。

内容的提问来源于stack exchange,提问作者bbd 666

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 15:21:10