Python Forum

Full Version: pygame music doesn't work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello

I'm going through the book 'making games with pygames', but I can't make python play music. The sound works fine but not the music

Here's my code:
soundObj = pygame.mixer.Sound('beep1.ogg')
soundObj.play()
import time
time.sleep(1)
soundObj.stop()

pygame.mixer.music.load('FFT.wav')
pygame.mixer.music.play(-1, 0.0)
pygame.mixer.music.stop()

while True:
	DISPLAYSURF.fill(WHITE)
	DISPLAYSURF.blit(textSurfaceObj, textRectObj)
	for event in pygame.event.get():
		if event.type == QUIT:
			pygame.quit()
			sys.exit()
	pygame.display.update()
If I play WAV files I get this error:ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
If I play MP3 files I get this: pygame.error: Unrecognized audio format
which i understand but pygame is suppose to recognize mp3 so.... (i tried playing with the name file in case i wrote FFT.mp3.mp3 but i get the same thing)
And if I play OGG files i get this: ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred

And like I said soundObj = pygame.mixer.Sound('beep1.ogg') works just fine.

Any help would be appreciated.

Thank you for your time.
(Dec-25-2020, 11:59 PM)CompleteNewb Wrote: [ -> ]hello

I'm going through the book 'making games with pygames', but I can't make python play music. The sound works fine but not the music

Here's my code:
soundObj = pygame.mixer.Sound('beep1.ogg')
soundObj.play()
import time
time.sleep(1)
soundObj.stop()

pygame.mixer.music.load('FFT.wav')
pygame.mixer.music.play(-1, 0.0)
pygame.mixer.music.stop()

while True:
	DISPLAYSURF.fill(WHITE)
	DISPLAYSURF.blit(textSurfaceObj, textRectObj)
	for event in pygame.event.get():
		if event.type == QUIT:
			pygame.quit()
			sys.exit()
	pygame.display.update()
If I play WAV files I get this error:ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
If I play MP3 files I get this: pygame.error: Unrecognized audio format
which i understand but pygame is suppose to recognize mp3 so.... (i tried playing with the name file in case i wrote FFT.mp3.mp3 but i get the same thing)
And if I play OGG files i get this: ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred

And like I said soundObj = pygame.mixer.Sound('beep1.ogg') works just fine.

Any help would be appreciated.

Thank you for your time.


This is because pygame only allows for the mixer to be used once, so if you delete sound and run it you will see that now the music plays. This is the same problem I have with a game I was working with. So you can leave the sound in and try use playsound for the music, it worked for me but it has like a delay before the file plays.