【问题标题】:pygame mixer not playing sound when window is not active当窗口不活动时,pygame混音器不播放声音
【发布时间】:2017-01-01 08:33:16
【问题描述】:

当 Pygame 窗口不活动时,Pygame 混音器不会播放音频。是否可以对其进行编程,即使在后台它也可以加载和播放新的声音文件? 下面是我的 pygame 代码。

from pygame import mixer
def playSound(file):
    mixer.quit()
    mixer.init(26000)
    file_path = "Sound/" + file + ".mp3"
    my_file = os.path.isfile(file_path)
    mixer.music.load(file_path)
    mixer.music.play()
    while mixer.music.get_busy():
        pass

【问题讨论】:

    标签: python-2.7 pygame


    【解决方案1】:

    我认为您的问题是您使用的是 python 2.7 而不是 3.5,当我运行此代码时,即使窗口未处于活动状态,我也会听到声音。更新带来了很多其他好处,所以我绝对会推荐它。

    【讨论】:

    • 感谢您的回复。实际上,由于一些库依赖问题,我无法迁移到 3.5。我使用的一些库仅在 Python 2.7 中受支持
    猜你喜欢
    • 1970-01-01
    • 2013-09-13
    • 2021-03-03
    • 2011-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-23
    相关资源
    最近更新 更多