In this Python Kivy article we want to learn about How to Play Video in Python Kivy, so Kivy is one of the popular Python GUI Framework and it is mostly user for building graphical user interfaces (GUIs). Kivy runs on different platforms like Windows, macOS, Linux, Android, and iOS. also Kivy includes powerful multimedia features that enable developers to play videos. in this article we want to talk how to play videos in Python Kivy.
First of all we need to instal Kivy and you can use pip for the installation.
1 |
pip install kivy |
After that you have installed Kivy, you can create a new Kivy application and play a video in just a few lines of code. this is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
from kivy.config import Config Config.set('kivy', 'video', 'ffmpeg') from kivy.app import App from kivy.uix.video import Video class MyApp(App): def build(self): video = Video(source='vid.mp4') video.state = 'play' return video if __name__ == '__main__': MyApp().run() |
In the above example we have created a new Kivy application at name of MyApp. in the build method, we have created a Video widget and set its source property to the path of the video we want to play. and at the end we return the Video widget from the build method.
Run the code and this will be the result

You can also play videos from URLs or from binary data. this is an example of playing a video from a URL:
1 2 3 4 5 6 7 8 9 10 11 |
from kivy.app import App from kivy.uix.video import Video class MyApp(App): def build(self): # create a Video widget video = Video(source='https://example.com/video.mp4') return video if __name__ == '__main__': MyApp().run() |
In the above example, we set the source property of the Video widget to a URL instead of a local file path.
And this is an example of playing a video from binary data:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
from kivy.app import App from kivy.uix.video import Video from io import BytesIO class MyApp(App): def build(self): # load the video as binary data with open('path/to/video.mp4', 'rb') as f: video_data = f.read() # create a Video widget from the binary data video = Video(source=BytesIO(video_data)) return video if __name__ == '__main__': MyApp().run() |
In the above example, we have loaded the video as binary data using open function and rb mode. after that we creates a BytesIO object from the binary data. and lastly we create a Video widget from the BytesIO object.