Skip to content Skip to sidebar Skip to footer

Pygame : Force Playing Next Song In Queue Even If Actual Song Isn't Finished? (aka "next" Button)

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? How can I ,with pygame, force the play of t

Solution 1:

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.

Code example for 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 stringsvar = 0

sound1.play()

while1:
    if next(): #whatever the next button trigger is
        queue[var].stop() # stop current songifvar == len(queue - 1): # if it's the last songvar = 0# set the var to represent the first songelse:
            var += 1# else, next song
        queue[var].play() # play the song var corresponds to

Post a Comment for "Pygame : Force Playing Next Song In Queue Even If Actual Song Isn't Finished? (aka "next" Button)"