import pygame file = 'some.mp3' pygame.init() pygame.mixer.init() pygame.mixer.music.load(file) pygame.mixer.music.play()
This outputs, "Process finished with exit code 0", but it doesn't play anything. How can I resolve this problem?
Pygame can load WAV, MP3, or OGG files. The difference between these audio file formats is explained at http://invpy.com/formats. To play this sound, call the Sound object's play() method. If you want to immediately stop the Sound object from playing call the stop() method.
Invoke pygame. mixer. music. play() to start playback of the music stream.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With