Play sounds in a loop from a list

后端 未结 1 377
生来不讨喜
生来不讨喜 2021-01-27 08:01

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

1条回答
  •  面向向阳花
    2021-01-27 08:38

    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:

    • pygame.mixer.music.queue

    0 讨论(0)
提交回复
热议问题