Kivy Tutorials
About Lesson

In this Python Kivy lesson we want to learn How to Play Mp3 Songs in Python Kivy,  for this we need to use SoundLoader class from kivy.core.audio.

 

 

We are going to create two examples, the first one will be an easy example, the second will be a little complex example. this is the first example code.

 

 

This is the complete code for this lesson 

 

 

 

 

In this line of code we have loaded our Mp3 music, make sure that you have added an Mp3 sound in your working directory, as i have already added the mp3 sound.

 

 

 

Run the code and this will be the result.

How to Play Mp3 Songs in Python Kivy
How to Play Mp3 Songs in Python Kivy

 

 

Now let’s create the second example, in this example we are going to create a button using our kivy file, and after that we want when a user clicks on the button, we want to play mp3 music.

 

 

So first create a python file, iam going to call it kivymusicapp.py, you can see that the first class extends from the FloatLayout, also we have added a method in this class for loading and playing our mp3 songs, because we will connect this method with the button that we create in the .kv file.

 

 

 

 

Now you need to create a .kv file, iam going to call it musicwindow.kv, make sure that your kv file name should be the same as your main App class, in my case my main window class name is MusicWindow, and my kv file name should be musicwindow.kv. in the kv file we have just created a button, and we have connected the button with the play_music() method that is located in our MyFloatLayout class.

 

 

 

Run the complete code and click on the button, you will have the music.

How to Play Mp3 Songs in Python Kivy
How to Play Mp3 Songs in Python Kivy