如下代码的意图是在播放了“bg_music.mp3”后再播放“splat.wav”。
疑惑在于,监测pygame.mixer.music
是否忙碌的代码pygame.mixer.music.get_busy()
将从一开始就执行,在系统仅仅执行到pygame.time.delay(1000)
的时候,pygame.mixer.music.get_busy()
应尚处于False状态,因此,“splat.wav”就理应先于“bg_music.mp3”播放才对吧?
import pygame, sys
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode([640,480])
pygame.time.delay(1000)
pygame.mixer.music.load("bg_music.mp3")
pygame.mixer.music.play()
splat = pygame.mixer.Sound("splat.wav")
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if not pygame.mixer.music.get_busy():
splat.play()
pygame.time.delay(1000)
for the splat sound to finish
running = False
pygame.quit()
前面不是先加载并播放
bg_music.mp3
的吗?只有当其播放完了才会播放splat