audio – Playing mp3 song on python

audio – Playing mp3 song on python

Grab the VLC Python module,, which provides full support for libVLC and pop that in site-packages. Then:

>>> import vlc
>>> p = vlc.MediaPlayer(file:///path/to/track.mp3)

And you can stop it with:

>>> p.stop()

That module offers plenty beyond that (like pretty much anything the VLC media player can do), but thats the simplest and most effective means of playing one MP3.

You could play with os.path a bit to get it to find the path to the MP3 for you, given the filename and possibly limiting the search directories.

Full documentation and pre-prepared modules are available here. Current versions are Python 3 compatible.

Try this. Its simplistic, but probably not the best method.

from pygame import mixer  # Load the popular external library

mixer.init() Klinik1-Anak Sekolah.mp3)

Please note that pygames support for MP3 is limited. Also, as pointed out by Samy Bencherif, there wont be any silly pygame window popup when you run the above code.

Installation is simple

$pip install pygame


Above code will only play the music if ran interactively, since the play() call will execute instantaneously and the script will exit. To avoid this, you could instead use the following to wait for the music to finish playing and then exit the program, when running the code as a script.

import time
from pygame import mixer

while  # wait for music to finish playing

audio – Playing mp3 song on python

See also playsound

pip install playsound

import playsound
playsound.playsound(/path/to/filename.mp3, True)

Leave a Reply

Your email address will not be published. Required fields are marked *