Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my PyGame mixer play sounds,?

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")
pygame.mixer.Sound.play(song)

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

like image 969
user164814 Avatar asked Dec 26 '22 21:12

user164814


1 Answers

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.

like image 112
SimonT Avatar answered Jan 02 '23 07:01

SimonT