- Kivy Tutorial
- Kivy - Home
- Kivy Basics
- Kivy - Getting Started
- Kivy - Installation
- Kivy - Architecture
- Kivy - File Syntax
- Kivy - Applications
- Kivy - Hello World
- Kivy - App Life Cycle
- Kivy - Events
- Kivy - Properties
- Kivy - Inputs
- Kivy - Behaviors
- Kivy Buttons
- Kivy - Buttons
- Kivy - Button Events
- Kivy - Button Colors
- Kivy - Button Size
- Kivy - Button Position
- Kivy - Round Buttons
- Kivy - Disabled Buttons
- Kivy - Image Button
- Kivy Widgets
- Kivy - Widgets
- Kivy - Label
- Kivy - Text Input
- Kivy - Canvas
- Kivy - Line
- Kivy - Checkbox
- Kivy - Dropdown List
- Kivy - Windows
- Kivy - ScrollView
- Kivy - Carousel
- Kivy - Slider
- Kivy - Images
- Kivy - Popup
- Kivy - Switch
- Kivy - Spinner
- Kivy - Splitter
- Kivy - Progress Bar
- Kivy - Bubble
- Kivy - Tabbed Panel
- Kivy - Scatter
- Kivy - Accordion
- Kivy - File Chooser
- Kivy - Color Picker
- Kivy - Code Input
- Kivy - Modal View
- Kivy - Toggle Button
- Kivy - Camera
- Kivy - Tree View
- Kivy - reStructuredText
- Kivy - Action Bar
- Kivy - Video Player
- Kivy - Stencil View
- Kivy - VKeyboard
- Kivy - Touch Ripple
- Kivy - Audio
- Kivy - Videos
- Kivy - Spelling
- Kivy - Effects
- Kivy - Input Recorder
- Kivy - OpenGL
- Kivy - Text
- Kivy - Text Markup
- Kivy - Settings
- Kivy Layouts
- Kivy - Layouts
- Kivy - Float Layout
- Kivy - Grid Layouts
- Kivy - Box Layouts
- Kivy - Stack Layout
- Kivy - Anchor Layout
- Kivy - Relative Layout
- Kivy - Page Layout
- Kivy - Recycle Layout
- Kivy - Layouts in Layouts
- Kivy Advanced Concepts
- Kivy - Configuration Object
- Kivy - Atlas
- Kivy - Data Loader
- Kivy - Cache Manager
- Kivy - Console
- Kivy - Animation
- Kivy - Multistroke
- Kivy - Clock
- Kivy - SVGs
- Kivy - UrlRequest
- Kivy - Clipboard
- Kivy - Factory
- Kivy - Gesture
- Kivy - Language
- Kivy - Graphics
- Kivy - Drawing
- Kivy - Packaging
- Kivy - Garden
- Kivy - Storage
- Kivy - Vector
- Kivy - Utils
- Kivy - Inspector
- Kivy - Tools
- Kivy - Logger
- Kivy - Framebuffer
- Kivy Applications and Projects
- Kivy - Drawing App
- Kivy - Calculator App
- Kivy - Stopwatch App
- Kivy - Camera Handling
- Kivy - Image Viewer
- Kivy - Bezier
- Kivy - Canvas Stress
- Kivy - Circle Drawing
- Kivy - Widget Animation
- Kivy - Miscellaneous
- Kivy Useful Resources
- Kivy - Quick Guide
- Kivy - Useful Resources
- Kivy - Discussion
Kivy - Video Player
The VideoPlayer widget in Kivy library is a ready to use control to play a video file and control its playback and sound. It is a predefined layout with the playing area and buttons to play/stop and pause/resume playback. It also has a seekbar with which the play position can be moved to a desired place.
The VideoPlayer class is defined in the "kivy.uix.videoplayer" module.
from kivy.uix.videoplayer import VideoPlayer player = VideoPlayer(**kwargs)
You need to assign the source property of a VideoPlayer object with a String representing the video file to be played. Kivy supports different video formats including "mp4", "avi" and "mpg".
To start the video, you should set the state property to 'play'
from kivy.uix.videoplayer import VideoPlayer player = VideoPlayer(source = "test.mp4") player.state = 'play'
One of the important features of Kivy's VideoPlayer is its ability to display text annotations at specific position in the video and for a certain duration. The annotations are provided in a file with ".jsa" extension, and with the same name as that of the video file.
The .jsa file is a JSON based file format. It contains the values for start position of the annotation, the duration in seconds for which it is displayed on the screen, and the annotation text.
[ {"start": 0, "duration": 2, "text": "Introduction"}, {"start": 10, "duration": 5, "text": "Hello World"}, ]
To keep the video playing in a loop, set the eos option to loop −
options={'eos': 'loop'}
The VideoPlayer class defines the following properties −
source − The source of the video to read. source is a StringProperty representing the path of the video file to be played
state − A string, indicates whether to play, pause, or stop the video. state is an OptionProperty and defaults to 'stop'.
allow_fullscreen − By default, you can double-tap on the video to make it fullscreen. Set this property to False to prevent this behavior.
position − Position of the video between 0 and duration. The position defaults to -1 and is set to the real position when the video is loaded.
seek(percent, precise=True) − Change the position to a percentage (strictly, a proportion) of duration. The percent value should be a float or int and between 0-1. The precise parameter is a bool, defaults to True where precise seeking is slower, but seeks to exact requested percent.
thumbnail − Thumbnail of the video to show. If None, VideoPlayer will try to find the thumbnail from the source + '.png'.
volume − Volume of the video in the range 0-1. 1 means full volume and 0 means mute.
annotation − The VideoPlayer uses a VideoPlayerAnnotation object to construct annotations, based on the JSON data stored in a JSA file.
Following keys are allowed to be used in JSA file −
start − The position at which the annotation is to be displayed
duration − Time for which the annotation label is displayed on the player window.
text − The text to be displayed as annotation.
bgcolor − [r, g, b, a] - background color of the text box
bgsource − 'filename' - background image used for the background text box
border − (n, e, s, w) - border used for the background image
Example
Th following code renders a video player widget on the application window −
from kivy.app import App from kivy.uix.videoplayer import VideoPlayer from kivy.core.window import Window Window.size = (720, 350) class MainApp(App): title = "Simple Video" def build(self): player = VideoPlayer( source="video.mp4", size_hint=(0.8, 0.8), options={'fit_mode': 'contain'} ) player.state = 'play' player.options = {'eos': 'loop'} player.allow_stretch = True return player MainApp().run()
Output
Run the code and check the output −
To Continue Learning Please Login
Login with Google