def playmusic2(soundfile):
"""Stream music with mixer.music module using the event module to wait
until the playback has finished.
This method doesn't use a busy/poll loop, but has the disadvantage that
you neet to initialize the video module to use the event module.
Also, interrupting the playback with Ctrl-C does not work :-(
Change the call to 'playmusic' in the 'main' function to 'playmusic2'
to use this method.
"""
pygame.init()
pygame.mixer.music.load(soundfile)
pygame.mixer.music.set_endevent(pygame.constants.USEREVENT)
pygame.event.set_allowed(pygame.constants.USEREVENT)
pygame.mixer.music.play()
pygame.event.wait()
评论列表
文章目录