pygame.mixer.Sound().play() 没有错误但实际上不播放
pygame.mixer.Sound().play() gives no error but actually does not play
我正在尝试使用 pygame
播放 .wav 文件
import pygame
pygame.mixer.init()
s = pygame.mixer.Sound('absolute path to file')
s.play()
没有报错,但好像什么都没播放。
这是完整的输出
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
在 conda python 3.6 环境中通过 pip 安装 pygame。 mac 使用 macOS Mojave
预订 2019 年专业版
最后加一行:
input ('Press enter to continue.')
你会听到的。您的脚本还没来得及播放声音就结束了。
正如 bashBediam 所说,问题是代码结束时没有给音频播放时间。我修复了这样做。
import pygame
pygame.mixer.init()
s = pygame.mixer.Sound(path)
channel = s.play()
while channel.get_busy():
pygame.time.wait(100)
我正在尝试使用 pygame
播放 .wav 文件import pygame
pygame.mixer.init()
s = pygame.mixer.Sound('absolute path to file')
s.play()
没有报错,但好像什么都没播放。
这是完整的输出
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
在 conda python 3.6 环境中通过 pip 安装 pygame。 mac 使用 macOS Mojave
预订 2019 年专业版最后加一行:
input ('Press enter to continue.')
你会听到的。您的脚本还没来得及播放声音就结束了。
正如 bashBediam 所说,问题是代码结束时没有给音频播放时间。我修复了这样做。
import pygame
pygame.mixer.init()
s = pygame.mixer.Sound(path)
channel = s.play()
while channel.get_busy():
pygame.time.wait(100)