How can I play an mp3 with pygame?

The play function starts the music playing, but returns immediately. Then your program reaches it’s end, and the pygame object is automatically destroyed which causes the music to stop.

As you commented, it does play the music if you wait for it before exiting – because then the pygame object isn’t destroyed until the while loop finishes.

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

Leave a Comment