Search code examples
pythonaudiomp3pyglet

Trouble playing an MP3 file in python via Pyglet


Summary: (Trying to play MP3 in python via pyglet library, AVbin not detected, Mp3 not played)

So i'm trying to to play an MP3 file in python with pyglet. i installed pyglet with the command prompt and all that good stuff, and I went to the AVbin website and downloaded and ran their .exe file. Im not sure if just running the .exe file actually installs AVbin, but that's all ive done with it so far. So my problem is im trying to play an mp3 that i have located on my desktop, but Pyglet still doesnt recognize AVbin? Here's the code as well as the error message:

Code:

import pyglet

music = pyglet.media.load(r"C:\Users\Doug\Desktop\01 Gem Shards - 4A.mp3")
music.play()

pyglet.app.run()

Error:

Traceback (most recent call last):
  File "C:/Python34/test.py", line 3, in <module>
    music = pyglet.media.load(r"C:\Users\Doug\Desktop\01 Gem Shards - 4A.mp3")
  File "C:\Python34\lib\site-packages\pyglet-1.2.3a1-py3.4.egg\pyglet\media\__init__.py", line 1429, in load
    source = get_source_loader().load(filename, file)
  File "C:\Python34\lib\site-packages\pyglet-1.2.3a1-py3.4.egg\pyglet\media\__init__.py", line 1410, in load
    return riff.WaveSource(filename, file)
  File "C:\Python34\lib\site-packages\pyglet-1.2.3a1-py3.4.egg\pyglet\media\riff.py", line 201, in __init__
    'AVbin is required to decode compressed media')
pyglet.media.riff.WAVEFormatException: AVbin is required to decode compressed media

Solution

  • Add AvBin to your PATH enviroment variable:

    you can do this with the folowwing command

    setx path "%path%;c:\pathToAvBin"
    

    plase note that you need to change "c:\pathToAvBin" for your real path to av bin :)

    BE CAREFULL TO NOT CLEAR YOUR PATH