In this lesson we want to learn How to Create Media Player with Python & Kivy, Kivy is an open source library for creating multitouch applications with natural user interface (NUI) for different devices. It is written in Python and Cython and can run on multiple platforms, including Windows, macOS, Linux, iOS and Android. Kivy is often used for creating games, mobile apps, and other interactive applications. It also supports different input methods such as multitouch, mouse, keyboard and others.
Creating media player with Kivy involves different steps:
- Install Kivy: you will need to install the Kivy library in order to use it for building your media player. you can install it using pip by running pip install kivy in your command prompt.
- Design the user interface: you will need to design user interface for your media player using Kivy’s built in widgets such as buttons, labels, etc. you can use .kv file to define layout of your media player.
- Add functionality: After that UI is designed, you will need to add functionality to your media player. for example, you will need to add buttons to play, pause and stop the media, as well as slider to adjust volume.
- Integrate media playback: finally you will need to integrate media playback into your media player. you can use Kivy’s builtin media player or use third party library such as pyglet or vlc-python.
This is an example of a basic media player with play, pause and stop buttons using Kivy:
from kivy.app import App
from kivy.uix.videoplayer import VideoPlayer
#pip install ffpyplayer
player = VideoPlayer(source='vid.mp4')
if __name__ == '__main__':
This code creates a Kivy app with a VideoPlayer widget as the root widget, and sets the source of the video to be played to ‘vid.mp4’. When the app is run, the video specified in the source will be played in the VideoPlayer widget.
Make sure that you have already install ffplayer, if you have not installed that it will not work.
pip install ffpyplayer
Learn More on Python GUI Development
- How to Use Qt Designer in PyQt and PyQt6
- Build Text to Speech App with Python & PyQt5
- How to Build GUI Window in PyQt6
- How to Show Image in PyQt6
- How to Create Calendar with Python & PyQt6
- How to Create CheckBox with Qt Designer & PyQt6
Run the complete code and this will be the result