1

I am working on an application that plays mp3 files using Python 3.5.2 running in IDLE with pygame 1.9.3.The problem is that some mp3 files play correctly and others do not play at all.

Test code used to evaluate the problem:

import pygame
from pygame import mixer
from pygame.locals import *
pygame.init()
mixer.init()
mixer.music.load('good.mp3')
mixer.music.play()
u = input('Good file')
mixer.music.load('bad.mp3')
mixer.music.play()
u = input('Bad file')

The file labeled 'good' plays correctly, while the one labled 'bad' does not. Both files are in the same directory; both files play with a music player; and both files work with python 3.4 and pygame on a Windows 7 machine.

user7823241
  • 230
  • 2
  • 10

2 Answers2

1

Pygame has never had good MP3 support. Per the docs: "Be aware that MP3 support is limited. On some systems an unsupported format can crash the program, e.g. Debian Linux. Consider using OGG instead."

http://www.pygame.org/docs/ref/music.html

FWIW, I've never had a problem with OGG files, and it's pretty easy to convert using ffmpeg or an online converter.

Chris
  • 898
  • 1
  • 5
  • 8
  • Unfortunately, that's not a practical solution for this application. – user7823241 Aug 27 '17 at 21:09
  • But using this method solves the problem does it not? It would then be a solution,albeit not the optimal solution? https://stackoverflow.com/questions/5464912/simple-way-to-transcode-mp3-to-ogg-in-python-live – srattigan Aug 27 '17 at 21:20
1

It may be a problem with the pygame support of mp3. Can you try the VLC module?

>>> import vlc
>>> p = vlc.MediaPlayer("bad.mp3")
>>> p.play()

If that doesn't work, you might try converting mp3 -> wav -> mp3 to fix any encoding problems which may be problematic for pygame. As suggested by chris, ffmpeg is the easiest way to encode.

$ ffmpeg -i bad.mp3 -acodec pcm_u8 bad.wav
$ ffmpeg -i bad.wav -codec:a libmp3lame -qscale:a 2 bad2.mp3
schollz
  • 178
  • 8