¿Por qué mi mezclador PyGame no reproduce sonidos?

My PyGame mixer in 2.7 won't work with the sound option. I can make it work with mixer.music but not with mixer.sound, with mixer.sound it makes a small ticking noise and then stops. Code:

import pygame
pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
song = pygame.mixer.Sound("song.mp3")

No error, it just won't play and gives a small ticking noise. On windows 7-x64 btw.

preguntado el 09 de septiembre de 13 a las 22:09

4 Respuestas

Usually, Pygame will not play mp3 files. You could test to see if .wav and .ogg files will play first, to make sure your code is correct (based on what you pasted, it seems to be right). I suggest converting your mp3 sounds to ogg for Pygame.

Respondido el 16 de Septiembre de 13 a las 00:09

Interesting. When I use Audacity to convert an MP3 to a Wave, Pygame won't play it. But when I convert MP3 to Ogg Vorbis it works. Any sounds that were Wave to begin with will play, however. Any reason why? - galeno nare

@GalenNare I'm not a Pygame guru but my best prediction is that you might have made a .wav with certain codecs or weird settings in Audacity, while the "native" wav files were more ordinary. - SimónT

This is exactly what I was looking for as an answer. Switched sound format and suddenly it was working. - Tim Holt

you just created an object called song.

instead of "pygame.mixer.Sound.play(song)" try this:


Respondido el 06 de enero de 15 a las 22:01

This can easily be solved because your song file should be loaded as music, not as a normal sound. Therefore, the following code makes it work perfectly:

import pygame
pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)

Respondido 05 Oct 13, 20:10

While a song is better off with the music module, the music module does not have any capabilities for different file types that the mixer module lacks. - trevorkirkby

In this case, one should use music module for .mp3 files as they will not play on the mixer module. - zenofpython

While it is better to use the music module, what I am saying is that even then it won't always support mp3 file format. - trevorkirkby

Pygame does play mp3 files. I had the same problem but I found out the solution:

si guardó su archivo mp3 como 'nombre de archivo.mp3', y usted mismo anotó la extensión de archivo .mp3, entonces el nombre de archivo en la función pygame.mixer.music.load() de pygame debe escribirse como 'nombre de archivo.mp3.mp3' , porque python espera que agregues el archivo .mp3. A veces, el .mp3 ya está incluido en el nombre del archivo si lo guardó manualmente como tal.

Por lo tanto, intente esto: pygame.mixer.music.load('filename.mp3.mp3')

Respondido 21 Jul 14, 04:07

"Hide extensions for known file types" should never have been a setting on windows... - Eric

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.