Hansi Schmidt
Hansi Schmidt

Reputation: 85

Play sounds in a loop from a list

i got this list awith 2 sounds and i want to play them with this code. Unfortunally it plays only the last sound of the list. I know that using pygame.Sound is a solution, but i don't know how to use it.

array = ["a.mp3", "b.mp3"] 
for i in range(len(array)):
    pygame.mixer.music.load(array[i])
    pygame.mixer.music.play()

Upvotes: 0

Views: 846

Answers (1)

Pedro Lobito
Pedro Lobito

Reputation: 99081

I was able to play music with pygame only after creating a display, i.e.:

import pygame
pygame.init()
pygame.display.set_mode(pygame.display.list_modes()[-1]) # smallest resolution available
pygame.mixer.init()
pygame.mixer.music.load('1.mp3')
pygame.mixer.music.play()
pygame.mixer.music.queue('2.mp3')

while pygame.mixer.music.get_busy():
    pygame.time.Clock().tick(10)

Notes:

Upvotes: 3

Related Questions