Pygame:即使实际歌曲未完成,也强制播放队列中的下一首歌曲?(又名“下一步"按钮) [英] Pygame : force playing next song in queue even if actual song isn't finished? (aka "Next" button)

查看:57
本文介绍了Pygame:即使实际歌曲未完成,也强制播放队列中的下一首歌曲?(又名“下一步"按钮)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 pygame 制作与随身听相同的功能:播放、暂停、排队都可以.但是如何做上一个/下一个按钮?

I want to make with pygame the same functionalities as a walkman : play, pause , queuing is ok.But how to do the previous/next buttons?

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

How can I ,with pygame, force the play of the next song which has been queued (and pass the ong which is actually playing?)

推荐答案

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

Have a list of song titles, and keep track of where you are in the list with a variable. Whether you are using pygame.mixer.music or pygame.mixer.Sound, when the "next" button is clicked, just have the variable change by one, and then stop the song, and have song the variable corresponds to play instead.

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

这篇关于Pygame:即使实际歌曲未完成,也强制播放队列中的下一首歌曲?(又名“下一步"按钮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆