Pygame:强制播放队列中的下一首歌曲,即使实际歌曲没有完成?(又称“下一步”按钮)

2024-05-16 18:53:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我想让pygame具有与随身听一样的功能:播放、暂停、排队好吧。但是如何执行“上一步/下一步”按钮?在

如何使用pygame,强制播放已排队的下一首歌曲(并传递实际正在播放的ong)在


Tags: 功能歌曲按钮pygame排队ong
1条回答
网友
1楼 · 发布于 2024-05-16 18:53:04

有一个歌曲标题的列表,并用一个变量跟踪你在列表中的位置。无论您使用的是pygame.mixer.music还是pygame.mixer.Sound,当单击“下一步”按钮时,只需将变量更改一次,然后停止歌曲,让变量对应的歌曲播放。在

pygame.mixer.Sound的代码示例:

#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

相关问题 更多 >