Playing MP3 File in Kivy Using Python

Learn how to play MP3 file in Python using Kivy.

Play MP3 File in Kivy Using SoundLoader in Python

Here we are going to play mp3 file in kivy using Python Programming Language. In kivy mp3 sound files are implemented using the SoundLoader module which is present in It is imported as follows

from import SoundLoader

The SoundLoader consists of various operations to be performed on sound files as follows

  • load(): This will help us to load the mp3 file.
  • play(): This is used to play the mp3 file.
  • stop(): It is used to stop playing an mp3 file.

The following code gives a complete implementation of playing a sound file.

import kivy
from import App
from kivy.uix.label import Label
from import SoundLoader
class music(App):
    def build(self):
        return Label(text="music playing")
    if sound:


Play MP3 File in Kivy Using SoundLoader in Python

We get the output as a kivy window with description music playing and the mp3 file gets played as soon as the kivy window is opened.

from import App

This will help us to create a window on which we will perform our operations.

from import SoundLoader

It will import the modules that are necessary for executing sound files in kivy.


This will load the mp3 file and we are assigning this to an object called sound.

if sound:

Here, the sound object returns True only if it’s a sound file and we are playing sound using play() with the help of a sound object.

5 responses to “Playing MP3 File in Kivy Using Python”

  1. Lemarchand says:

    Hello, this was what I’ve been looking for. I mean I have the ideas but you code it.
    Now I have to gain more practice with kivy and try to make something more complicated.

  2. sunil shrimali says:

    after building app i cannot able to access music file, i am using os module to fetch all mp3 files

  3. Deepak says:

    Place .py file and music files in same folder.

  4. Izzat says:

    Hi can can u check my code its not working. I worked with kivymd please help me to solve this

    from kivy.lang import Builder
    from kivymd.uix.list import OneLineListItem
    from import MDApp
    from import SoundLoader
    import os

    helper_string = “””
    orientation: “vertical”
    id: scroll


    class MainApp(MDApp):
    def build(self):
    self.sound = None
    screen = Builder.load_string(helper_string)
    return screen

    def on_start(self):
    for root, dirs, files in os.walk(‘E:/music/’):
    for file in files:
    if file.endswith(‘.mp3’):
    required_file = file
    the_location = os.path.abspath(required_file)
    self.root.ids.scroll.add_widget(OneLineListItem(text=required_file, on_release=self.play_song))

    def play_song(self, onelinelistitem):
    the_song_path = onelinelistitem.text
    if self.sound:
    self.sound = SoundLoader.load(the_song_path)
    if self.sound:


  5. Manohar says:

    Thank you very much I just copied the code and it worked. I was searching for this code for weeks thanks again

Leave a Reply

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