听不到我想玩 pygame 的声音 [英] Can't hear the sounds I am tring to play with pygame

查看:55
本文介绍了听不到我想玩 pygame 的声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听不到我试图用 pygame 播放的声音.这是我的代码.

I can't hear the sounds I am trying to play with pygame. This is my code.

import pygame
pygame.init()



pygame.mixer.music.load(r"C:\Users\Isaiah\Desktop\easy_going.mp3")
pygame.mixer.music.play()

任何帮助都会很棒!

谢谢!

推荐答案

MP3 支持受限于 Pygame;改用 .wav.幸运的是,您可以使用在线转换工具轻松地将 .mp3 文件转换为 .wav 文件.

MP3 support is limited with Pygame; use .wav instead. Fortunately you can easily convert .mp3 files to .wav files with an online conversions tool.

您还需要在最后添加一个延迟循环,以防止您的程序过早关闭.

You also need to add a delay loop at the end to keep your program from closing prematurely.

将您的 .mp3 转换为 .wav,然后尝试运行此修改后的代码.

Convert your .mp3 to a .wav and then try running this modified code.

import pygame

#Replaced init() with mixer.init() 
pygame.mixer.init()

sound = pygame.mixer.Sound(r"C:\Users\Isaiah\Desktop\easy_going.wav")
s = pygame.mixer.Sound.play(sound)

#Delay loop
while s.get_busy():
    pygame.time.delay(100)

祝你好运!

这篇关于听不到我想玩 pygame 的声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆