pygame.error: mixer not initialized和pygame.error: WASAPI can‘t find requested audio endpoint: 找不到元素。 | 您所在的位置:网站首页 › 石油有机成因说明书下载 › pygame.error: mixer not initialized和pygame.error: WASAPI can‘t find requested audio endpoint: 找不到元素。 |
在使用Python开发游戏时难免会用到Pygame模块,其中该模块有个关于声音函数,使用该函数我们可以为我们的游戏添加音效。 问题描述:要使用声音模块我们就必须在主函数开头初始化我们的游戏,因此我们在主函数的开头就添加以下语句来初始化游戏。 # 游戏初始化 pygame.init()但是当我运行程序时,发现游戏窗口出现闪退的情况,并且出现报错信息,如下: D:\Game\TankWar\venv\Scripts\python.exe D:/Game/TankWar/main.py pygame 2.0.2 (SDL 2.0.16, Python 3.8.5) Hello from the pygame community. https://www.pygame.org/contribute.html Traceback (most recent call last): File "D:/Game/TankWar/main.py", line 41, in is_quit_game = run_Game(config) File "D:/Game/TankWar/main.py", line 22, in run_Game sounds[key] = pygame.mixer.Sound(value) pygame.error: mixer not initialized Process finished with exit code 1 它竟然说我没有初始化mixer!!!没办法,我们就按他那个报错走嘛,给他再单独初始化一下mixer。 pygame.init() pygame.mixer.init()我***你个***!!!还是出现以下报错信息,游戏窗口照样闪退。 D:\Game\TankWar\venv\Scripts\python.exe D:/Game/TankWar/main.py pygame 2.0.2 (SDL 2.0.16, Python 3.8.5) Hello from the pygame community. https://www.pygame.org/contribute.html Traceback (most recent call last): File "D:/Game/TankWar/main.py", line 42, in is_quit_game = run_Game(config) File "D:/Game/TankWar/main.py", line 17, in run_Game pygame.mixer.init() pygame.error: WASAPI can't find requested audio endpoint: 找不到元素。 Process finished with exit code 1 解决方案:经过我反复测试发现,它竟然有的时候可以正常运行,有的时候就会出现以上报错。终于我找到了一位大佬的文章,解决了这个问题。 耳机的问题!!!因为我用的是台式机并且没有连接音响,所以一直没有音频输出设备这导致pygame不知道在哪里输出声音(在这种情况下无法找到音频设备),从而引发错误。插入音频设备(即我的耳机)后,就…就解决了。。。 |
CopyRight 2018-2019 实验室设备网 版权所有 |