繁体   English   中英

音乐无法在Python / Pygame中运行

[英]Music not working in Python/Pygame

我尝试查找它并且有多种解决方案,但它们都不适合我

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)

抛出错误

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

我也发现了这个我能做到的事情:

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

在我pygame的项目,但是我不能在它的中间,甚至当我把它放在一个线程阻止这一切。 有解决方案吗

Ps:我正在使用mac 10.11.6

更新:我复制了pickle.aifc并将其转换为pickle.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)

根据文档Pygame canbot处理文件格式,如.aiffc。

解决方案是将您的文件转换为.wav: https//cloudconvert.com/aifc-to-wav

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM