本文介绍了从列表循环播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了带有2种声音的列表,我想用此代码播放它们.不幸的是,它仅播放列表中的最后一个声音.我知道使用pygame.Sound是一种解决方案,但我不知道如何使用它.

i got this list awith 2 sounds and i want to play them with this code.Unfortunally it plays only the last sound of the list. I know that using pygame.Sound is a solution, but i don't know how to use it.

array = ["a.mp3", "b.mp3"]
for i in range(len(array)):
    pygame.mixer.music.load(array[i])
    pygame.mixer.music.play()

推荐答案

创建display后,我只能使用pygame 播放音乐,即:

I was able to play music with pygame only after creating a display, i.e.:

import pygame
pygame.init()
pygame.display.set_mode(pygame.display.list_modes()[-1]) # smallest resolution available
pygame.mixer.init()
pygame.mixer.music.load('1.mp3')
pygame.mixer.music.play()
pygame.mixer.music.queue('2.mp3')

while pygame.mixer.music.get_busy():
    pygame.time.Clock().tick(10)


注释:

这篇关于从列表循环播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 15:03