我正在寻找一种方法来查看pygame.mixer.Channel当前是否正在播放声音。因此,例如,只有在特定通道中的声音播放完成后才执行某些操作。下面是我当前播放声音的代码:
import pygame
pygame.mixer.pre_init()
pygame.mixer.init()
pygame.init()
pygame.mixer.Channel(0).play(pygame.mixer.Sound('coolsound.wav'), maxtime=2000)我在考虑一个if语句,类似于:
if pygame.mixer.Channel(0) = playing a sound:
print("playing a sound")
else:
print("not playing")显然这是行不通的,只是为了让你知道我在找什么。谢谢!
发布于 2019-01-31 03:25:20
我得到答案了。使用get_busy(),我能够检查通道是否正在播放声音,它返回True或False。以下是我的最终代码:
if pygame.mixer.Channel(0).get_busy() == True:
print("playing a sound")
else:
print("not playing")以下是文档的链接,以了解更多信息:https://www.pygame.org/docs/ref/mixer.html#pygame.mixer.get_busy
https://stackoverflow.com/questions/54444765
复制相似问题