0

I am currently trying to incorporate some audio in a game I am creating in python 3.2.3. and pygame. I am currently receiving the following error:

Traceback (most recent call last):
  File "E:\FinalProject.py", line 57, in <module>
    BackMusic = pygame.mixer.Sound('Background Music.mp3')
pygame.error: Unable to open file 'Background Music.mp3'

with the following code:

pygame.mixer.init(44100,-16,300, 1024)
BackMusic = pygame.mixer.Sound('Background Music.mp3')
Sound.play()

This is my first time working with loading audio files so I'm not really sure why python is unable to load the while when the file is in the same folder as the program. Any help is appreciated.

  • Add this code to see exactly your program path. import os; print (os.getcwd()); – Valijon Jun 17 '14 at 05:37
  • possible duplicate of [Why doesn't my PyGame mixer play sounds,?](http://stackoverflow.com/questions/18706991/why-doesnt-my-pygame-mixer-play-sounds) – sloth Jun 17 '14 at 06:33

2 Answers2

0

For a long time I have also had problems with loading special types of .mp3 files. I think it depends on the "special type" in some kind?

So my solution was to use .wav PCM linear files

-1

Same error has been discussed on Why doesn't my PyGame mixer play sounds,?

Usually, Pygame will not play mp3 files. But, you can load your sound as music

import pygame
pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
pygame.mixer.music.load("Background Music.mp3")
pygame.mixer.music.play()
Community
  • 1
  • 1
Valijon
  • 12,667
  • 4
  • 34
  • 67
  • I think the music module still has the same issues with mp3 files. The docs say "Be aware that MP3 support is limited." so it may or may not work. – elParaguayo Jun 17 '14 at 08:33