在Python/Pygam中不工作的音乐

2024-05-17 13:00:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着查了一下,有多种解决方案,但都不适合我。在

import pygame

pygame.init()

pygame.mixer.init()
pygame.mixer.music.load('Pickle.aifc')
pygame.mixer.music.play(0)

display = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Music Test")

clock = pygame.time.Clock()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()
            exit()

    pygame.display.update()
    clock.tick(60)

抛出错误

^{pr2}$

我还发现了一个我可以做的事情:

import subprocess
subprocess.call(['afplay', 'Pickle.aifc'])

然而,在我的pygame项目中,即使我把它放到一个线程中,我也不能中途停止。有什么解决办法吗?在

Ps:我用的是mac 10.11.6

更新:我复制了泡菜.aifc把它变成泡菜.aiff,我仍然得到一个非常类似的错误:

  File "/Users/William/PycharmProjects/My Games/Examples/MusicTest/Main.py", line 12, in <module>
    pygame.mixer.music.load('Pickle.aiff')
pygame.error: Unrecognized file type (not AIFF)

Tags: inimporteventinittypedisplaymusicload