Video¶
Video plays local and remote video in a native
player view, and a ref on it publishes a
VideoHandle. Enable it with use = ["video"]
under [plugins]. See the Video guide.
Video playback: a native player view with a typed handle.
Enable it in pythonnative.toml:
Example
Classes:
| Name | Description |
|---|---|
VideoInfo |
What |
VideoHandle |
The handle a |
Functions:
| Name | Description |
|---|---|
Video |
Play a local or remote video in a native player view. |
Attributes:
| Name | Type | Description |
|---|---|---|
ResizeMode |
How the picture fits its view: letterboxed, cropped to fill, or distorted to fill. |
|
VideoSource |
An |
ResizeMode
module-attribute
¶
ResizeMode = Literal['contain', 'cover', 'stretch']
How the picture fits its view: letterboxed, cropped to fill, or distorted to fill.
VideoSource
module-attribute
¶
An http(s) URL, a file path, a bundled Asset, or a path under app/assets/.
VideoInfo
dataclass
¶
VideoHandle
¶
Bases: ViewHandle
The handle a ref on Video receives.
Methods:
| Name | Description |
|---|---|
play |
Start or resume playback. A video that has ended restarts from the beginning. |
pause |
Pause playback. |
seek |
Jump to |
position |
Return the current playback position in seconds. |
Video
¶
Video(
source: Optional[VideoSource] = None,
*,
controls: bool = False,
autoplay: bool = False,
loop: bool = False,
muted: bool = False,
volume: float = 1.0,
rate: float = 1.0,
resize_mode: ResizeMode = "contain",
poster: Optional[VideoSource] = None,
progress_interval: float = 0.25,
on_ready: Optional[Callable[[VideoInfo], Any]] = None,
on_progress: Optional[
Callable[[float, float], Any]
] = None,
on_end: Optional[Callable[[], Any]] = None,
on_error: Optional[Callable[[str], Any]] = None,
on_buffering: Optional[Callable[[bool], Any]] = None,
style: StyleProp = None,
ref: Optional[Ref] = None,
key: Optional[str] = None
) -> Element
Play a local or remote video in a native player view.
The view has no intrinsic size, so give it one through style: a
width and height, or a flex, or an aspect_ratio inside a
sized parent. Passing a ref publishes a
VideoHandle on ref.current.
The player releases its resources when the view unmounts. When the app goes to the background, playback pauses and resumes on return; Android also frees the decoder until then, since a device has few of them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Optional[VideoSource]
|
What to play: an |
None
|
controls
|
bool
|
Show the platform's playback controls
( |
False
|
autoplay
|
bool
|
Start playing as soon as the video is ready. |
False
|
loop
|
bool
|
Restart at the end. A looping video doesn't fire |
False
|
muted
|
bool
|
Silence the audio track without changing |
False
|
volume
|
float
|
Audio level from |
1.0
|
rate
|
float
|
Playback speed, where |
1.0
|
resize_mode
|
ResizeMode
|
How the picture fits the view. |
'contain'
|
poster
|
Optional[VideoSource]
|
An image shown until playback starts, as a URL, a file path, or an asset. |
None
|
progress_interval
|
float
|
Seconds between |
0.25
|
on_ready
|
Optional[Callable[[VideoInfo], Any]]
|
Called with a |
None
|
on_progress
|
Optional[Callable[[float, float], Any]]
|
Called with |
None
|
on_end
|
Optional[Callable[[], Any]]
|
Called when playback reaches the end. |
None
|
on_error
|
Optional[Callable[[str], Any]]
|
Called with a message when the source can't load or play. |
None
|
on_buffering
|
Optional[Callable[[bool], Any]]
|
Called with |
None
|
style
|
StyleProp
|
Style dict (or list of dicts). |
None
|
ref
|
Optional[Ref]
|
Optional |
None
|
key
|
Optional[str]
|
Stable identity for keyed reconciliation. |
None
|
Returns:
| Type | Description |
|---|---|
Element
|
An |
Raises:
| Type | Description |
|---|---|
PluginNotEnabledError
|
On a device whose build doesn't include
|