I’ve been having problems trying to load and play sounds in pygame. Most people seem to have trouble with MP3s but for some reason, I can’t even get wavs to play.
>>> f=open('menuscreen.wav',"rb")
>>> pygame.mixer.init()
>>> pygame.mixer.music.load(f)
Traceback (most recent call last):
File "<string>", line 1, in <fragment>
pygame.error: Module format not recognized
and neither does this work:
>>> k = pygame.mixer.Sound('menuscreen.wav')
>>> pygame.mixer.init()
>>> pygame.mixer.music.load(k)
Traceback (most recent call last):
File "<string>", line 1, in <fragment>
pygame.error: Couldn't read from RWops
and neither does this:
>>> import pygame
>>> pygame.mixer.init()
>>> pygame.mixer.music.load('menuscreen.wav')
Traceback (most recent call last):
File "<string>", line 1, in <fragment>
pygame.error: Unable to load WAV file
I’m using 2.7.2 and pygame 1.9.1
You should load the file by passing the file name as first argument. This works on my system (same python and pygame versions) just fine:
HTH!