recipe-521884.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:code 作者: ActiveState 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号