tkSnack:当第一个声音结束时如何播放第二个声音

时间:2013-10-23 10:28:14

标签: python

我希望我的脚本在第一个声音结束时播放第二个声音。来自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.

所以,我认为在播放一首歌时调用声音对象上的播放方法会导致第二首歌在这首歌完成时启动。

不幸的是,这似乎没有发生。事实上,当我在声音对象上调用read方法时,为了加载音频文件,播放器停止播放。

我应该如何加载音频?

我也试过使用两种不同的声音对象,但这会导致重叠播放。

到目前为止,我发现的唯一解决方案是对blocking方法使用play选项。并将其添加到循环中:

for song in songList:
    SoundObject.read(song)
    SoundObject.play(blocking=True)

然而,这远不是一个好的解决方案,因为它会阻止整个应用程序,即使我在守护程序线程中启动它。

以下是示例代码:

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它会将音轨“附加”到当前音轨并在第一个音频结束后立即启动。

0 个答案:

没有答案