- 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 - Videos
The Video widget in Kivy framework capable of displaying video files and streams. The video formats you can play with Video widget depend on the operating system, video provider installed along with plugins required if any. The GStreamer provider is capable of handling almost any video codecs such as mpg, avi, mp4, mov, etc.
The Video class is defined in the "kivy.uix.video" module.
from kivy.uix.video import Video vid = Video(**args)
The only mandatory parameter required to the constructor is the source property - a string representing the path to a video file.
vid = Video(source = "test.mp4")
In order to start the video playback, you need to set its play property to True. You can pass this parameter in the constructor to start the video as soon as it is loaded, or set it to True/False as and when required.
# start playing the video at creation video = Video(source='test.mp4', play=True) # create the video, and start later video = Video(source='test.mp4') # and later video.play = True
Other properties of Video class are listed below −
duration − Duration of the video. The duration defaults to "-1", and is set to a real duration when the video is loaded.
eos − Stands for "end of stream". A Boolean property indicates whether the video has finished playing or not (reached the end of the stream).
play − Indicates whether the video is playing or not. You can start/stop the video by setting this property to True or False.
position − Position of the video between 0 and duration. The position defaults to -1 and is set to a real position when the video is loaded.
seek() − Change the position to seek as a proportion of the total duration, must be between 0-1.
state − A string, indicating whether to play, pause, or stop the video −
# start playing the video at creation video = Video(source='test.mp4', state='play') # create the video, and start later video = Video(source='test.mp4') # and later video.state = 'play'
volume − Volume of the video, in the range 0-1. 1 means full volume, 0 means mute.
Example
from kivy.app import App from kivy.uix.videoplayer import VideoPlayer from kivy.uix.video import Video from kivy.core.window import Window Window.size = (720,400) class MainApp(App): title = "Simple Video" def build(self): player = Video(source = "earth.mp4", size_hint = (1,1), options={'fit_mode': 'contain'}) player.state = 'play' player.options = {'eos': 'loop'} player.allow_stretch=True return player MainApp().run()
Output
The video playback starts as you run the above code −
To Continue Learning Please Login
Login with Google