gpt4 book ai didi

python - PyGame 不播放音乐

转载 作者:行者123 更新时间:2023-12-03 02:03:47 26 4
gpt4 key购买 nike

我有一些简单的代码可以在 Python 3.4 中使用 PyGame 播放声音。

import pygame
file = 'Henesys.ogg' # this file exists in current directory
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load(file)
pygame.mixer.music.play(0)
pygame.event.wait()

但是,当我运行它时,它不起作用。在 IDLE 中运行时,解释器外壳不再是响应式(Reactive)的(如预期的那样),但没有声音播放。我不确定为什么。我在互联网上搜索,发现人们可以毫无问题地运行此代码。我无法确定问题可能出在哪里。

有人可以告诉我我做错了什么吗?

作为引用,我的操作系统是 Windows 7 64 位,安装了 Python 3.4.3 和 Pygame(从轮子安装: pygame-1.9.2a0-cp34-none-32.whl )。

另外作为引用,platform.architecture() 返回 ('32bit', 'WindowsPE')。

谢谢你。

最佳答案

您可以尝试的第一件事是更改

pygame.mixer.music.play(0)

线到
pygame.mixer.music.play(0, 0.0)

正如我在 the PyGame site 上发现的那样,“pygame.mixer.music.play()”有两个参数。

您可以尝试的第二件事是更改
pygame.mixer.music.load(file)


pygame.mixer.music.load("Henesys.ogg")

关于python - PyGame 不播放音乐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29222196/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com