This is our ninth article in Python Kivy, in this article we are going to learn How to Play Video in Python Kivy, the Video
widget is used to display video files and streams. Depending on your Video core provider, platform, and plugins, you will be able to play different formats. For example, the pygame video provider only supports MPEG1 on Linux and OSX. GStreamer is more versatile, and can read many video containers and codecs such as MKV, OGV, AVI, MOV, FLV (if the correct gstreamer plugins are installed). Our VideoBase
implementation is used under the hood.
So before starting our coding you need to install these two libraries, if you don’t do this there will be error when you play the video in kivy.
1 2 |
pip install ffpyplayer pip install pillow |
Kivy Crash Course Articles
1: Kivy Crash Course Introduction & Installation
2: Introduction to Kv Design Language
5: How to Create CheckBox in Kivy
6: Kivy Image And AsyncImage Example
7: How to Create Slider in Python Kivy
8: How to Create TextInput in Python Kivy
Also you can watch the complete video for this article
So now this is the complete source code for Python Kivy How to Play Video
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from kivy.app import App from kivy.uix.video import Video from kivy.uix.widget import Widget class VideoWindow(App): def build(self): video = Video(source='myvideo.mp4') video.state = 'play' video.options = {'eos': 'loop'} video.allow_stretch = True return video if __name__ == "__main__": window = VideoWindow() window.run() |
OK in the above code, first of all i have imported the required modules from kivy, after that i have created my class the extends from the App class, and i have created the object of my video widget. and there are different attributes that you can use with kivy video widget.
- duration: duration of the video. The duration defaults to -1, and is set to a real duration when the video is loaded.
duration
is aNumericProperty
and defaults to -1. - eos: boolean, indicates whether the video has finished playing or not (reached the end of the stream).
eos
is aBooleanProperty
and defaults to False. - loaded: boolean, indicates whether the video is loaded and ready for playback or not.
loaded
is aBooleanProperty
and defaults to False. - options: options to pass at Video core object creation.
If you run the code this will be the result
Subscribe and Get Free Video Courses & Articles in your Email
Can you do this within a kivy String?