Pygame mixer in a subprocess does not work

孤人 提交于 2019-12-10 18:46:50

问题


Debian OS. I call a subprocess

subprocess.Popen([sys.executable, "/home/pi/play_sound.py"])

And in play_sound.py, I play a sound with:

def load_sound(url):
    class NoneSound:
        def play(self): pass
    if not pygame.mixer or not pygame.mixer.get_init():
        return NoneSound()
    fullname = url
    try:
        sound = pygame.mixer.Sound(fullname)
    except pygame.error, message:
        print 'Cannot load sound:', fullname
        raise SystemExit, message
    return sound

The problem is that when I run play_sound.py separately, it works fine. But when I call it as a subprocess of another py file, it does not play the sound.

来源:https://stackoverflow.com/questions/15926065/pygame-mixer-in-a-subprocess-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!