Playing Videos With Kivy

Kivy has a video player which supports common requirements such as play,pause and stop buttons and images, texts can be used as subtitles or displaying messages to user, streching etc. For the full list, you can check here.

In this example, a simple video player having autoplay feature will be written with both Python and Kivy.

Firstly, the main Python file consists of these lines:

#-*-coding:utf-8-*-

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout


class RootWidget(BoxLayout):
    pass

class VideoPlayerApp(App):
    def build(self):
        return RootWidget()

if __name__ == "__main__":
    VideoPlayerApp().run()

And the kv file is very easy as well:

<RootWidget>:
    VideoPlayer:
        source: "videoplayback.avi"
        state: "play"

The source takes the file name/path to play and the state determines the state of playing such as play or pause.

If you want to give it a chance, you can play with it even with one line of console code. The console code will be as given:

python -m kivy.uix.videoplayer videoplayback.avi

These two are identical but the first one has the opportunity of adding more widgets. Consult the documentation before you write the code.

 
comments powered by Disqus