Can't hear the sounds I am tring to play with pygame

百般思念 提交于 2020-02-03 12:12:29

问题


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()

Any help would be great!

Thanks!


回答1:


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.

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)

Good luck!



来源:https://stackoverflow.com/questions/59957315/cant-hear-the-sounds-i-am-tring-to-play-with-pygame

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!