The IDAJ Show
The IDAJ Show

Reputation: 65

Can't hear the sounds I am tring to play with 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()

Any help would be great!

Thanks!

Upvotes: 4

Views: 155

Answers (1)

David Greydanus
David Greydanus

Reputation: 2567

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!

Upvotes: 4

Related Questions