Pygame error when loading sound: module format is not recognized

I am having problems loading and playing sounds in pygame. Most people seem to have problems with MP3s, but for some reason I can't even play WAV.

>>> 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 this also does not 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 does not do 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 am using 2.7.2 and pygame 1.9.1

+4
source share
1 answer

You must load the file by passing the file name as the first argument. This works on my system (same versions of python and pygame) just fine:

 >>> import pygame >>> pygame.mixer.init() >>> pygame.mixer.music.load('filename.wav') >>> pygame.mixer.music.play() 

NTN!

+5
source

Source: https://habr.com/ru/post/1384765/


All Articles