栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

pygame.error: mixer not initialized和pygame.error: WASAPI can‘t find requested audio endpoint: 找不到元素。

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

pygame.error: mixer not initialized和pygame.error: WASAPI can‘t find requested audio endpoint: 找不到元素。

在使用Python开发游戏时难免会用到Pygame模块,其中该模块有个关于声音函数,使用该函数我们可以为我们的游戏添加音效。


问题描述:

要使用声音模块我们就必须在主函数开头初始化我们的游戏,因此我们在主函数的开头就添加以下语句来初始化游戏。

# 游戏初始化
    pygame.init()

但是当我运行程序时,发现游戏窗口出现闪退的情况,并且出现报错信息,如下:

D:GametankWarvenvscriptspython.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:GametankWarvenvscriptspython.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不知道在哪里输出声音(在这种情况下无法找到音频设备),从而引发错误。插入音频设备(即我的耳机)后,就…就解决了。。。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/354672.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号