问题
I'm playing around with Pygame on my Mac, running OSX Yosemite. I can't get it to play an MP3 file using the following code:
pygame.mixer.music.load('bg_music.mp3')
pygame.error: Unrecognized music format
I'm using Python 2.7.1 and have the following libraries installed:
- sdl (brew): 1.2.15
- sdl_mixer (brew): 1.2.12
- libvorbis (brew): 1.3.4
- pygame: 1.9.2a0
I've searched around and tried all the suggestions on this thread without success.
Does anyone have any ideas how I can get this thing to work?
回答1:
Do you have SMPEG library installed? libvorbis is used for .ogg support, .mp3 requires either SMPEG or MAD libraries, as stated in SDL_mixer manual.
回答2:
I had the same issue, thanks the Cynikal's post I was finally able to resolve this. You can ignore step2 if you have already installed pygame. Also change pip3 to pip and remove python3 from the brew install list if you plan to use python27 or something
Step 1: Install all Pygame deps for Mac with Brew (if you don't have brew, look up how to install first)
brew install python3 hg sdl sdl_image sdl_ttf portmidi smpeg
Step 2: Install PyGame
pip3 install hg+http://bitbucket.org/pygame/pygame
Step 3: Download sdl-mixer source code from: https://www.libsdl.org/projects/SDL_mixer/release-1.2.html
Untar the tar.gz file with tar zxvf:
tar zxvf SDL_mixer-1.2.12.tar.gz
cd SDL_mixer-1.2.12
./configure
make
sudo make install
Step 4: Run your pygame code and see if it fixes your dependency issue
I hope this helps others who come to this with the same issue I had on OS X Yosemite
回答3:
My problem was that I was using python 2 instead of python3
回答4:
I also faced same problem its because of pygame version 1.9.5 my problem was sloved when I installed 1.9.6 version try this command it really worked:
python -m pip install pygame==1.9.6.rc1 --user --pre
来源:https://stackoverflow.com/questions/28173743/pygame-on-osx-yosemite-unrecognized-music-format