pygame.error:混合器未初始化如何解决?

时间:2020-06-01 03:23:33

标签: python python-3.x audio pygame

所以我正在将声音加载到游戏中,但出现此错误 我正在使用python 3 Windows 10

pygame.error: mixer not initialized

我尝试过推杆,但是当我推杆时得到了

pygame.mixer.init()

当我放入pygame.mixer.init()时,出现此错误?我必须导入一些东西吗?

pygame.error: DirectSoundCreate: No audio device found
import pygame
import math

pygame.init()

pygame.mixer.init()


# window
window = pygame.display.set_mode((800,800))
pygame.display.set_caption("new World")
#
# error bloccks
erblock = pygame.image.load("error.png")

# trees images
treo = pygame.image.load("tree.png")

# mountains
mounto = pygame.image.load("mount.png")

# platform images
blocks = pygame.image.load("block.png")

# coins image
heart = pygame.image.load("heart.png")

# heart image
heartingss = pygame.image.load("health.png")



# define the shooting sound for the player ------------------------
shootsound = pygame.mixer.Sound("ss.wav")

# hit enemy sound
hitenemysound = pygame.mixer.Sound("hitenemy.wav")


# sound for jumping
jumpsound = pygame.mixer.Sound("sjump.wav")

# pick up coins sound
coinssound = pygame.mixer.Sound("coinssound.wav")

# shoot sound
shots = pygame.mixer.Sound("shootsound.wav")

# hit the ice sound
icehit = pygame.mixer.Sound("h.wav")

# health power UP
powerup = pygame.mixer.Sound("pw.wav")


# load this sound if the player is dead
death = pygame.mixer.Sound("death.wav")

# walking sound
walk = pygame.mixer.Sound("walks.wav")

# background music
music = pygame.mixer.Sound("backgroundsong.wav")
pygame.mixer.music.play(-1)

2 个答案:

答案 0 :(得分:0)

nvm稍后在工作时修复了它,我不知道如何大声笑

答案 1 :(得分:0)

我也遇到了如下所示的类似错误:

pygame.error: WASAPI can't find requested audio endpoint: Element not found.

我意识到,我忘记将耳机插入台式机了,这意味着台式机没有音频输出设备。这导致pygame不知道声音输出到哪里(在您的情况下无法找到音频设备),从而引发错误。

插入音频设备(即我的耳机)后,它的工作原理就像一个吊饰!