Skip to content Skip to sidebar Skip to footer

Playing Music With Pygame Unreliable

I'm trying to write a simple program to play music files with Pygame. My script is below. import pygame import sys import time FRAMERATE = 30 if len(sys.argv) < 2: sys.exi

Solution 1:

I imagine this is because the actual music playback is happening on another thread, so it sometimes hasn't finished starting at the point you first call get_busy().

If that's the case, it seems like a bug in either pygame or SDL_mixer (which pygame uses.)

As an alternative way of checking for music completion, you can get pygame to give you an event when the music finishes and check for that. Like this:

pygame.mixer.music.set_endevent(pygame.USEREVENT)

quit = Falsewhilenot quit:
   clock.tick(FRAMERATE)
   foreventin pygame.event.get():
      ifevent.type == pygame.QUIT: 
        quit = Trueifevent.type == pygame.USEREVENT: 
        print "Music ended"
        quit = True

Post a Comment for "Playing Music With Pygame Unreliable"