【问题标题】:PyGame not playing musicPyGame 不播放音乐
【发布时间】:2015-03-23 23:16:48
【问题描述】:

我有一些简单的代码可以在 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 中运行时,解释器外壳不再是反应式的(如预期的那样),但没有声音播放。我不确定为什么。我在互联网上搜索,发现人们可以毫无问题地运行此代码。我无法确定问题可能出在哪里。

谁能告诉我我做错了什么?

作为参考,我的操作系统是 Windows 7 64bit,安装了 Python 3.4.3 和 Pygame(从 wheel 安装:pygame-1.9.2a0-cp34-none-32.whl)。

也供参考,platform.architecture() 返回 ('32bit', 'WindowsPE')。

谢谢。

【问题讨论】:

    标签: python audio pygame


    【解决方案1】:

    你可以尝试的第一件事就是改变

    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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-30
      • 2019-05-06
      • 1970-01-01
      • 2011-02-25
      • 2018-12-27
      • 2021-05-05
      相关资源
      最近更新 更多