website/docs/controls/video/index.md
import TabItem from '@theme/TabItem'; import Tabs from '@theme/Tabs'; import {ClassAll, CodeExample} from '@site/src/components/crocodocs';
Embed a full-featured video player in your Flet app with playlist support, hardware acceleration controls, and subtitle configuration.
It is powered by the media_kit Flutter package.
| Platform | Windows | macOS | Linux | iOS | Android | Web |
|---|---|---|---|---|---|---|
| Supported | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Add the flet-video package to your project dependencies:
requirements.txt or pyproject.toml.
</TabItem>
The below sections show the required configurations for each platform.
You may need to declare and request file-system/storage permissions, depending on your use case:
android.permission.READ_MEDIA_AUDIO (optional): Allows to read audio files from external storage. Android 13 or higher.android.permission.READ_MEDIA_VIDEO (optional): Allows to read video files from external storage. Android 13 or higher.android.permission.READ_EXTERNAL_STORAGE (optional): Allows reading from external storage. Android 12 or lower.android.permission.WRITE_EXTERNAL_STORAGE (optional): Allows writing to external storage. Android 12 or lower.See also:
libmpv libraries must be installed and present on the machine running the app.
On Ubuntu/Debian, this can be done with:
sudo apt install libmpv-dev mpv
If you encounter libmpv.so.1 load errors, run:
sudo apt update
sudo apt install libmpv-dev libmpv2
sudo ln -s /usr/lib/x86_64-linux-gnu/libmpv.so /usr/lib/libmpv.so.1
<CodeExample path={frontMatter.examples + '/basic/main.py'} language="python" />
Drive playback programmatically with methods like
[play()][flet_video.Video.play], [pause()][flet_video.Video.pause], [stop()][flet_video.Video.stop], [seek()][flet_video.Video.seek], [next()][flet_video.Video.next], and [previous()][flet_video.Video.previous],
and inspect status with methods like [is_playing()][flet_video.Video.is_playing], [get_current_position()][flet_video.Video.get_current_position], and [get_duration()][flet_video.Video.get_duration].
<CodeExample path={frontMatter.examples + '/playback/main.py'} language="python" />
Shows how to capture the current video frame with
[take_screenshot()][flet_video.Video.take_screenshot] and display it as an image.
<CodeExample path={frontMatter.examples + '/screenshot/main.py'} language="python" />
Mutate [playlist][flet_video.Video.playlist] directly to add,
remove, or replace items, and navigate between tracks.
<CodeExample path={frontMatter.examples + '/playlist/main.py'} language="python" />
Listen for player events like
[on_load][flet_video.Video.on_load], [on_complete][flet_video.Video.on_complete], [on_track_change][flet_video.Video.on_track_change], etc.
<CodeExample path={frontMatter.examples + '/events/main.py'} language="python" />
Attach a [VideoSubtitleTrack][flet_video.VideoSubtitleTrack] (here, raw VTT text)
and customize its appearance with [VideoSubtitleConfiguration][flet_video.VideoSubtitleConfiguration].
<CodeExample path={frontMatter.examples + '/subtitles/main.py'} language="python" />
Switch between [AdaptiveVideoControls][flet_video.AdaptiveVideoControls], [MaterialVideoControls][flet_video.MaterialVideoControls], [MaterialDesktopVideoControls][flet_video.MaterialDesktopVideoControls], custom, and hidden control sets at runtime.
<CodeExample path={frontMatter.examples + '/controls/main.py'} language="python" />
Show different controls in normal vs. fullscreen mode by mapping each
[VideoControlsMode][flet_video.VideoControlsMode] to its own [controls][flet_video.Video.controls] value.
<CodeExample path={frontMatter.examples + '/controls_mode/main.py'} language="python" />
Customize the [primary_button_bar][flet_video.MaterialDesktopVideoControls.primary_button_bar],
[top_button_bar][flet_video.MaterialDesktopVideoControls.top_button_bar], and
[bottom_button_bar][flet_video.MaterialDesktopVideoControls.bottom_button_bar] of
[MaterialDesktopVideoControls][flet_video.MaterialDesktopVideoControls] with built-in and custom items.
<CodeExample path={frontMatter.examples + '/button_bars/main.py'} language="python" />