【问题标题】:pygame.error: mixer not initialized How To Fix?pygame.error:混音器未初始化如何修复?
【发布时间】:2020-06-01 03:23:33
【问题描述】:

所以我正在将声音加载到我的游戏中,但我收到了这个错误 我正在使用 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)

【问题讨论】:

  • 您能否编辑您的问题以包括操作系统和 Python + PyGame 版本
  • 是的,我添加了它我使用 python 3 windows 10

标签: python python-3.x audio pygame


【解决方案1】:

我也遇到了类似的错误:

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

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

插入音频设备(即我的耳机)后,它就像一个魅力!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    相关资源
    最近更新 更多