How can I play more than one song at a time in PyGame?

前端 未结 2 2109
花落未央
花落未央 2021-01-03 00:05

I\'ve got it working now but with the time delay is there a better way because I want two different scripts to be working I want to have these playing in this order and have

相关标签:
2条回答
  • 2021-01-03 00:25

    The following script will load 4 sounds (sound_0.wav to sound_3.wav) and play them.

    sounds = []
    for i in range(4):
        sound = pygame.mixer.Sound('sound_%d.wav'%i)
        sound.play()
        sounds.append(sound)
    
    0 讨论(0)
  • 2021-01-03 00:38

    Did you check the pygame.Mixer module ? On default, you can play 8 songs simultaneously

    If you use the pygame.mixer.music, you'll be able to play only one song at the time.

    If you use the pygame.mixer.sound, you'll be able to play up to 8 songs at the time.

    The music module is here to stream music (it doesn't load all the music file at once).

    The sound module is here to play differents sounds during game (sounds are completely loaded in memory).

    So, in your example if you want to play the 4 songs at the same time :

    import pygame
    pygame.mixer.init()
    pygame.mixer.pre_init(44100, -16, 2, 2048)
    pygame.init()
    print "hey I finaly got this working!"
    sounds = []
    sounds.append(pygame.mixer.Sound('D:/Users/John/Music/Music/FUN.OGG'))
    sounds.append(pygame.mixer.Sound('D:/Users/John/Music/Music/Still Alive.OGG'))
    sounds.append(pygame.mixer.Sound('D:/Users/John/Music/Music/turret.OGG'))
    sounds.append(pygame.mixer.Sound('D:/Users/John/Music/Music/portalend.OGG'))
    for sound in sounds:
        sound.play()
    
    0 讨论(0)
提交回复
热议问题