循环包含声音文件路径的列表 [英] Loop over a list containing path to sound files
本文介绍了循环包含声音文件路径的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我打算做的是遍历一个包含我的声音文件路径的列表,并在 python 中使用 pygame.mixer 模块播放它们,但是当我这样做时,我遇到的问题是 pygame 总是播放最后一个索引列表中的路径文件,其余部分被跳过.例如,如果我的列表包含 2 个项目:
So what I was planning to do was loop over a list which contains path to my sound files and play them using pygame.mixer module in python, but when I did this the problem I encountered was pygame always play the last most index path file from the list, and rest were skipped. Example if my list contains 2 items:
music_list = ['abc.mp3', 'gef.mp3']
for music_index in range(len(music_list)):
mixer.init()
mixer.music.load(music_list[music_index])
mixer.music.play()
then it never plays abc.mp3 file and directly plays the last file gef.mp3
推荐答案
使用 pygame.mixer.music.queue()
加载声音文件并排队:
Use pygame.mixer.music.queue()
to load sound files and queue it:
mixer.init()
mixer.music.load('abc.mp3')
mixer.music.play()
mixer.music.queue('gef.mp3')
这篇关于循环包含声音文件路径的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文