Video
Opens a video by URL, draws the frame and publishes what playback is doing. One word, not two: the element draws the picture itself , and its children lie on top of the frame. The simple case is one line.
Type:
multi-child
(children are a layer over the frame or the
id:loading
/
id:error
/
id:ready
slots)
Video src:"https://cdn.example.com/clip.mp4" poster:"https://cdn.example.com/cover.jpg"
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
src
/ (positional)
|
string | — |
Video address
with a scheme
(
https://…
). A path inside the project (
data/video/clip.mp4
) does not open:
status:"error"
|
url
|
string | — |
Same as
src
|
poster
|
string |
''
|
A picture
under
the layer of children until playback starts. A project path or an address, as in
Image src:
|
controls
|
bool | true |
Draw the built-in panel: play/pause, a position slider, elapsed and total time.
false
— when the controls are yours
|
#playback
|
structure | — | How to play, see below |
#surface
|
structure | — | How the frame fills the box, see below |
Outputs
| Parameter | Type | Description |
|---|---|---|
supported
|
output
@name
|
Whether the build has a player. Without one
poster
is shown and the rest is empty
|
status
|
output
@name
|
idle
/
loading
/
buffering
/
playing
/
paused
/
ended
/
error
/
unavailable
|
position
|
output
@name
|
Current position, seconds |
duration
|
output
@name
|
Length, seconds; empty until the metadata arrives |
play
|
output
@name
|
A ready "play" callback:
onPressed:$go
|
pause
|
output
@name
|
A ready "pause" callback |
seek
|
output
@name
|
A ready callback with a
position
argument in seconds:
onPressed:{to(position:0)}
|
Nested structures
#playback
| Parameter | Type | Default | Description |
|---|---|---|---|
autoplay
|
bool | false |
Start as soon as the source opens. Use together with
muted:true
. Hidden and shown again, it resumes by itself
|
muted
|
bool | false | Open without sound. Browsers allow autoplay only this way |
loop
|
bool | false |
Start over instead of
ended
|
background
|
bool | false |
Keep playing while hidden (another page on top, an inactive
IndexedStack
child,
Offstage
) — for music, radio, a stream
|
#surface
| Parameter | Type | Default | Description |
|---|---|---|---|
fit
|
contain
|
cover
|
fill
|
contain
|
How the frame fills the box — the same words as in
Image fit:
|
aspectRatio
|
double | 16 / 9 |
Shape of the box when neither
width
nor
height
is set
|
width
|
double | — | Box width, px |
height
|
double | — | Box height, px |
Video src:"https://cdn.example.com/loop.mp4"
#playback autoplay:true muted:true loop:true
#surface fit:cover aspectRatio:1
The poster is a layer, the slots are states
poster
lies
under
the children and stays until playback starts: the cover and the play button are visible at the same time. The
id:loading
/
id:error
slots replace the layer of children — a spinner while buffering, a line on failure.
id:ready
can be omitted: the first child without an
id
counts as it.
Your own buttons
The variables
Video
writes are visible only to its subtree, so the controls go
inside
— as a layer over the frame:
Video src:"https://cdn.example.com/clip.mp4" controls:false status:@st position:@pos play:@go pause:@stop seek:@to
CircularProgressIndicator id:loading
Text "The video did not open" id:error
Align id:ready alignment:bottomCenter
Row mainAxisSize:min
IconButton onPressed:(){st == "playing" ? stop() : go()} tooltip:"Play or pause"
Icon {st == "playing" ? "pause" : "play_arrow"}
IconButton onPressed:{to(position:0)} tooltip:"From the start"
Icon replay
Text $"${pos ?? 0} s"
Passing a callback and calling it are different forms.
onPressed:$go
passes it,
onPressed:(){… go() …}
calls it. A value expression
onPressed:{st == "playing" ? stop : go}
is neither: the button is drawn and does nothing.
Behavior
-
The source opens on the first tap
, not when the element appears. The platform has one player, so there can be any number of
Videoelements on screen — each shows its poster and holds nothing. Until the first tapstatusisidle,durationis unknown. The exception is#playback autoplay:true. -
A video that lost the player pauses and remembers its place
:
status→paused,positionis kept, the next tap continues from the same place. A live stream continues from the live point. -
Hidden means paused.
Covered by another page, in an inactive
IndexedStackchild, underOffstage offstage:true— it pauses. Shown again,autoplayresumes by itself, the others wait for a tap. One that left the tree (if:false) is closed. -
Changing
srccontinues rather than restarts : one that was playing plays the new clip, one that was stopped stays stopped and takes the player from nobody.
Differences between the app and the site
-
The site draws the browser's
<video>. Withoutcontrols:falsethe browser's panel is used (full screen, picture-in-picture, AirPlay), not the app's own panel: the player looks different on the site on purpose. -
#surfacebecomes the box shape (aspect-ratio) and the frame'sobject-fit,#playback muted/loop— attributes of<video>;poster— the<video>poster. - Slots and your own buttons work: the layer of children lies over the frame, and the page script updates the outputs.
- The browser could play several videos at once, but the page stops the others, as the app does.
-
On the site
if:falsehides rather than removes, so the player comes back paused in its place rather than from scratch.
See also
-
Image
—
fit, picture paths forposter - Device as data — generators with callbacks in variables
- Sound — sound without a picture