#setup pygame above this
#load sounds
sound1 = pygame.mixer.Sound("soundone.ogg")
sound2 = pygame.mixer.Sound("soundtwo.ogg")
queue = [sound1, sound2] #note that the list holds the sounds, not strings
var = 0
sound1.play()
while 1:
if next(): #whatever the next button trigger is
queue[var].stop() # stop current song
if var == len(queue - 1): # if it's the last song
var = 0 # set the var to represent the first song
else:
var += 1 # else, next song
queue[var].play() # play the song var corresponds to
有一个歌曲标题的列表,并用一个变量跟踪你在列表中的位置。无论您使用的是
pygame.mixer.music
还是pygame.mixer.Sound
,当单击“下一步”按钮时,只需将变量更改一次,然后停止歌曲,让变量对应的歌曲播放。在pygame.mixer.Sound
的代码示例:相关问题 更多 >
编程相关推荐