Sometimes, we want to play an mp3 with Python pygame.
In this article, we’ll look at how to play an mp3 with Python pygame.
How to play an mp3 with Python pygame?
To play an mp3 with Python pygame, we can call the pygame.time.Clock().tick
method in the while loop that we use the return value of pygame.mixer.music.get_busy
as the condition.
For instance, we write
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(10)
to keep the clip playing as long as pygame.mixer.music.get_busy
returns True
, which is when the clip is still being played.
Conclusion
To play an mp3 with Python pygame, we can call the pygame.time.Clock().tick
method in the while loop that we use the return value of pygame.mixer.music.get_busy
as the condition.