如何使用 pygame.mixer 重复播放音乐? [英] How do I repeat music using pygame.mixer?
本文介绍了如何使用 pygame.mixer 重复播放音乐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了以下使用 pygame.mixer 播放 mp3 音乐的代码.然而,音乐不会重复.关于我如何制作它以便音乐重复播放的任何想法?代码如下:
I have created the following code that plays mp3 music using pygame.mixer. However, the music does not repeat. Any idea's on how I would make it so that the music does repeat? Here is the code:
playlist = list()
playlist.append ( "put music here.mp3" )
playlist.append ( "put music here.mp3" )
pygame.mixer.music.load ( playlist.pop() )
pygame.mixer.music.queue ( playlist.pop() )
pygame.mixer.music.set_endevent ( pygame.USEREVENT )
pygame.mixer.music.play()
a = 0
running = True
while a == 0:
while running:
for event in pygame.event.get():
if event.type == pygame.USEREVENT:
if len ( playlist ) >1:
pygame.mixer.music.queue ( playlist.pop() )`
推荐答案
根据 pygame 文档 你可以为 pygame.mixer.music.play()
传入 -1
来无限重复播放音乐.
According to the pygame documentation you can pass in -1
for pygame.mixer.music.play()
to repeat the music indefinitely.
这篇关于如何使用 pygame.mixer 重复播放音乐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文