我希望我的脚本在第一个声音结束时播放第二个声音。来自tkSnack documentation:
play ( )
Plays the sound. All options are ignored if play() is used to resume a paused play options.
If a play() command is issued while another one is in progress,
the latter one is queued up and starts to play as soon as possible.
所以,我认为在播放一首歌的时候调用sound对象上的play方法会导致第二首歌在这首歌结束时开始。在
不幸的是,这似乎没有发生。实际上,当我对sound对象调用read
方法时,为了加载音频文件,播放器停止播放。在
如何加载音频?在
我也尝试过使用两个不同的声音对象,但这会导致重复播放。在
到目前为止,我找到的唯一解决方案是对play
方法使用blocking
选项。并将其添加到循环中:
然而,这远不是一个好的解决方案,因为它会阻塞整个应用程序,即使我在守护进程线程中启动它。在
下面是一个示例代码:
import Tkinter, tkSnack, time
win = Tkinter.Tk()
tkSnack.initializeSnack(win)
snd = tkSnack.Sound()
def play1():
snd.read('/home/francesco/Musica/Andrea Bocelli - Ave Maria.mp3')
snd.play()
def play2():
snd.read('/home/francesco/Musica/Andrea Bocelli - La voce del silenzio.mp3')
snd.play()
b1 = Tkinter.Button(win, text="play1", command = play1)
b2 = Tkinter.Button(win, text="play2", command = play2)
b1.pack()
b2.pack()
win.mainloop()
我很乐意点击play2
它将“附加”当前的一个配乐,并在第一个结束时立即启动它。在
目前没有回答
相关问题 更多 >
编程相关推荐