Video player
ProA video player complete with nothing set: its own controls, keys, touch gestures, captions and states over a file or a stream, drawn in the theme over any picture. Not an M3 component (@windmorph/react-pro).
import { VideoPlayer, VideoPlayerControl, VideoPlayerControlGroup, VideoPlayerVolume, VideoPlayerNotice, MediaSlider, useVideoPlayer } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Props
VideoPlayer 67 props
What plays: a file or a stream the browser plays itself (a string), or an engine's
{ attach(video) }returning a cleanup. It is set on the<video>only when playback is first asked for, so nothing downloads before. A changed source keeps the place.The picture shown until the first frame.
How the poster loads:
eagerfor a page's main image.Holds the poster back this many ms where this player follows another (a feed's next video), so it never flashes between the two.
The video's length in seconds, if known before anything loads, so the time shows at first paint.
The video's width, if known before anything loads: its shape turns and fits the picture.
The video's height, likewise.
The video's chapters, drawn on the scrubber.
Starts playing when it shows (muted, where the browser insists).
The volume, 0 to 1 (controlled).
The volume at first (uncontrolled).
Whether the sound is off (controlled). A mute the browser forced on a video that started by itself is never reported.
The sound off at first (uncontrolled).
The player's actions for an app outside it:
play,pause,seek(seconds),toggleFullScreenandtogglePictureInPicture(the last two only inside a press or key handler, which the browser asks for).The speed (controlled).
The speed at first (uncontrolled).
The speeds
<and>step through.playbackRatePresetstypereadonly (number | VideoPlayerSettingsSpeedPreset)[]default 1, 1.25, 1.5 and 2, those withinplaybackRatesThe settings' Playback speed presets, a press away (
VideoPlayerSettingsSpeed'spresets): speeds that fit the app's fastest one, a locked speed. The page's slider runs from the slowest to the fastest ofplaybackRates.Plays again from the start when it ends (controlled).
Loops at first (uncontrolled).
Offers Rotate: the button (fine pointers, from a 42rem player) and R and Shift+R.
The picture's turn in degrees, a multiple of 90 (controlled).
The turn at first (uncontrolled).
Autoplay's state (controlled): the player only shows and reports it; what follows a video is the app's. The switch shows, from a 38rem player, once
onAutoplayNextChangeis given.Autoplay at first (uncontrolled).
Theater mode (controlled): the player holds and reports it (
data-theater); the page's layout is the app's. The button and T show onceonTheaterChangeis given.Theater at first (uncontrolled).
The smallest window size class with the theater button and T.
The caption tracks: with any, a Captions button and C. The player draws them itself.
The language whose captions show,
nullfor none (controlled).Captions at first (uncontrolled).
Starts at this second, saying "Resumed from 12:34" with Start over until 8 seconds have played.
For a player in a feed:
pausepauses it whenever less than 60% of it is in view orcovered, however it was started;playalso starts it, muted with "Turn sound on", while in view (never under reduced motion, and not again once the person paused it). Whether the person allows it is the app's.Something lies over the player (a sheet, a dialog): with
inView, it pauses.The bar's look:
grouped, each control or group in its own see-through container (the default), orscrim, bare controls over a dark gradient at the foot.The app's own
VideoPlayerControls, at the end of the bar, before full screen. Where the bar has no room for them, each folds into the settings as a row (a switch for atoggle), after Theater mode and Picture-in-picture and before Next; its key still works. Anything else here stays on the bar.The settings companion (
<VideoPlayerSettings />): given it, a Settings button joins the bar after Captions, and the panel opens over the picture at the player's end corner, over its controls. With no rows of its own it draws Playback speed, Captions and Loop from the player, and Autoplay and Rotate where the bar has no room for them.The bar folds what doesn't fit into the settings, least important first: Rotate, Autoplay, Theater mode, Picture-in-picture, the app's
controls(the last first), Next, Captions, Mute, then the time (whose length gives way before any of them). Play, Settings and Full screen never fold. Each folded control is a row, shown first and not repeated where the settings already show it; without this prop, a Settings button of the player's own holds only those rows.A mark on the Settings button's icon (a quality tag), upright while the gear turns, hidden from assistive tech.
Over the picture when the video ends, in place of Replay there.
Replaces the player's icons.
The
<video>element, for the app (a glow behind the player, say).Other attributes for the
<video>(crossOrigin, say).Ref to the frame.
The frame's id.
Events
Called as playback starts.
Called as playback pauses.
Called as the video ends.
Called as the time moves, in seconds.
Called when the video can't load.
Called as the player enters or leaves full screen.
Called when the person changes the volume.
Called when the person mutes or unmutes.
Called when the speed changes.
Called when a speed preset is pressed, a disabled one included (a locked speed).
Called when Loop is switched.
Given, a Next button joins Play's container, with Shift+N.
Called when the picture turns.
Called when Autoplay is switched.
Called when theater is switched.
Called when captions come on, change or go off.
Called as the video enters or leaves picture-in-picture.
Text
Words the player says, with English defaults. A
LabelsProvidersets them for the whole app.The player's role description.
The Play button's name while paused.
The same button's name while playing.
Its name once the video has ended.
The sound button's name while there is sound.
Its name while muted.
The volume slider's name.
The scrubber's name.
The full-screen button's name.
Its name while in full screen.
Said while the first frame hasn't come.
Said after a key plays.
Said after a key pauses.
Said after M mutes.
Said after M unmutes.
Said and shown after a key moves the volume.
Said after a key skips back.
Said after a key skips forward.
The notice when the video can't load.
The notice's button.
The notice while offline.
The button shown while the browser started the video muted.
The Next button's name.
The Rotate button's name.
Said after a turn.
Said once the picture is upright again.
The Autoplay switch's name.
Its tooltip while on.
Its tooltip while off.
Its tooltip while Loop is on, which stops it.
The theater button's name, and its tooltip while off.
Its tooltip while on.
Said and shown after a key changes the speed.
The speed of 1, in words.
The Captions button's name.
Said and shown as captions come on.
Said and shown as they go off.
The picture-in-picture button's name.
Its name while on.
The note shown when it starts where it was left.
The note's button.
The Settings button's name, and the settings' own.
The Loop row in the settings.
The Off option of the Captions row.
One of
aria-labeloraria-labelledbyis required.One of
aria-labeloraria-labelledbyis required.
Classes for the frame: its size and corners. Wins over the defaults via
cn().Classes for each part.
The frame.
The
<video>.The poster picture.
The middle of the picture: Play, Replay, the waiting mark, a notice.
The mark a key leaves.
A notice over the picture (failed).
The layer of controls along the foot.
The scrubber's slot.
The row of containers under the scrubber.
Each see-through container on the bar.
Each button on the bar.
The time's container.
The caption lines over the picture.
The black bars beside or above and below the picture, where its shape leaves room.
The volume's container: the mute button and its slider.
"Turn sound on", at the top start while the browser holds the sound off.
The "Resumed from" note, at the top start.
The
endedslot's box over the picture.
Inline styles for the frame, e.g.
--wm-video-player-*tokens.
VideoPlayerControl 16 props
Its name.
Its icon.
Its tooltip, when it says more than the name (a state).
Its key (
S,Shift+S), shown in the tooltip, given asaria-keyshortcutsand bound while focus is in the player: it presses the control, or switches it. The player's own keys win.The icon while on, for an on and off control.
A mark on the icon's top end corner (a quality tag), inside the button, upright, hidden from assistive tech.
An on and off control:
aria-pressed, a filled icon on a ground while on.Whether it is on (controlled).
Whether it starts on (uncontrolled).
Can't be pressed.
Ref to the button.
The button's id.
Events
Called when it is switched.
Called when it is pressed.
VideoPlayerControlGroup 5 props
The controls it holds.
Ref to the container.
The container's id.
VideoPlayerVolume 4 props
VideoPlayerNotice 7 props
What it says.
Its icon, 32px.
A text button under it ("Try again").
Ref to the notice.
The notice's id.
MediaSlider 17 props
The value (controlled).
The value at first (uncontrolled).
The smallest value.
The largest value.
One step: an arrow key's move.
A larger step: Page Up and Page Down.
The value in words for screen readers (
aria-valuetext), "Volume 55%" or "1.5×".Can't be moved or focused.
The root's id.
The root element.
Events
Called as the value moves.
Called once a move ends (a drag let go, a key).
Text
One of
aria-labeloraria-labelledbyis required.One of
aria-labeloraria-labelledbyis required.
Classes for the root; they win over the component's own (
cn()).Classes for each part.
Inline styles for the root, e.g.
--wm-media-slider-*tokens.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Types
VideoPlayerPoster 3 fields
The poster: the picture shown until the first frame.
VideoPlayerCaptionTrack 3 fields
A caption track the app gives the player.
Its language, a BCP 47 code ("en", "fr-CA"): its name is said in the reader's language.
The WebVTT file.
Its name, where the language's name isn't enough ("English, with descriptions").
Hooks
useVideoPlayer
Inside a VideoPlayer: its state and actions.
Returns VideoPlayerState
The speed, and the speeds offered.
The picture's turn, in degrees.
Autoplay's state, and whether the app offers it.
What has loaded, as the element reports it.
The caption tracks, the one showing (
nullfor none), and the way to choose one.Theater mode, and whether the app offers it.
Enters or leaves full screen (only inside a press or key handler).
Picture-in-picture: whether it's on, whether the browser has it, and the way in and out.
The player's width class, by its own width:
compactunder 30rem (round buttons, no volume slider),mediumunder 42rem (Autoplay and Rotate in the settings),expandedfrom 42rem.compactuntil measured, as on the server.
Spec status
Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.
| Item | Status | Details |
|---|---|---|
| A file, with nothing set | Built | Configuration · Basic |
Captions and chapters (captions, chapters) | Built | Configuration · Controls |
Next, Rotate, Autoplay and Theater (onNext, rotatable, onAutoplayNextChange, onTheaterChange) | Built | Configuration · Controls |
Speeds and the settings' presets, one of them locked (playbackRates, playbackRatePresets, onPlaybackRatePresetPress) | Built | Configuration · Speeds |
Looks: grouped and scrim (look) | Built | Variant · Look |
A control of your own and content at the end (controls, ended) | Built | Configuration · Look |
A stream an engine drives (source={{ attach }}) | Built | Use case · Engine |
| Not an M3 component | Extension | M3 has no video player; this one is built from the core’s icon buttons, tooltips and loading indicator in a dark scope over the picture, with Pro’s MediaTimeSlider as its scrubber. |
| One look over any picture | Extension | The shared on-media tokens keep every word at 4.5:1 and every icon and focus ring at 3:1 over a white or a black frame, with a fallback fill under reduced transparency. |
| Nothing downloads before Play | Extension | The source is set on the <video> (or the engine attached) only when playback is first asked for, so a page of players loads only their posters. |
A file, with nothing set
BuiltConfiguration · Basic
Captions and chapters (
Builtcaptions,chapters)Configuration · Controls
Next, Rotate, Autoplay and Theater (
BuiltonNext,rotatable,onAutoplayNextChange,onTheaterChange)Configuration · Controls
Speeds and the settings' presets, one of them locked (
BuiltplaybackRates,playbackRatePresets,onPlaybackRatePresetPress)Configuration · Speeds
Looks: grouped and scrim (
Builtlook)Variant · Look
A control of your own and content at the end (
Builtcontrols,ended)Configuration · Look
A stream an engine drives (
Builtsource={{ attach }})Use case · Engine
Not an M3 component
ExtensionM3 has no video player; this one is built from the core’s icon buttons, tooltips and loading indicator in a dark scope over the picture, with Pro’s
MediaTimeSlideras its scrubber.One look over any picture
ExtensionThe shared on-media tokens keep every word at 4.5:1 and every icon and focus ring at 3:1 over a white or a black frame, with a fallback fill under reduced transparency.
Nothing downloads before Play
ExtensionThe source is set on the
<video>(or the engine attached) only when playback is first asked for, so a page of players loads only their posters.
Theming & tokens
The controls are in a dark scope over the picture in every theme. Their colours, see-through fill, blur, state layers and the two-tone focus ring are the shared --wm-on-media-* tokens below, which the settings panel and the side arrows of FeaturedCarousel and Shelf read too, so one override reaches all of them. Under reduced transparency, or without backdrop-filter, the fill is the fallback colour without the blur. The player's own --wm-video-player-* tokens set its sizes, insets and timing; its scrubber takes the --wm-media-time-slider-* tokens. className goes on the frame (its size and corners); style each part with classNames: root, video, poster, middle, mark, notice, controls, scrubber, bar, container, control, time, captions, bars, volume, sound, resumed, ended.
| Variable | Default | Paints |
|---|---|---|
--wm-video-player-inset-inline | 12px | The controls’ distance from the player’s sides (the scrubber’s too). |
--wm-video-player-inset-bottom | 8px | The controls’ distance from the player’s foot. |
--wm-video-player-container-height | 40px | A container’s height: 4px round 32px buttons. |
--wm-video-player-container-padding | 4px | The space inside a container, round its buttons. |
--wm-video-player-container-gap | 8px | The space between containers. |
--wm-video-player-button-gap | 2px | The space between the buttons in one container. |
--wm-video-player-icon-size | 24px | A bar button’s icon, in its 32px button (M3’s extra-small icon is 20px). |
--wm-video-player-grouped-button-width | 48px | A button in a shared container, from a 30rem player (round below). |
--wm-video-player-time-padding | 12px | The time’s side padding in its container. |
--wm-video-player-time-padding-wide | 16px | The same, from a 30rem player. |
--wm-video-player-on-ground | color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent) | The ground of a control that is on (captions on, say); its icon is filled. |
--wm-video-player-mark-ground | color-mix(in srgb, var(--md-sys-color-scrim) 56%, transparent) | The ground of the mark a key leaves in the middle. |
--wm-video-player-notice-ground | color-mix(in srgb, var(--md-sys-color-scrim) 72%, transparent) | The ground of a notice over the picture (failed, offline). |
--wm-video-player-scrubber-gap | 4px | The space between the scrubber’s slot and the containers. |
--wm-video-player-scrubber-slot | 20px | The scrubber’s slot over the containers (its 48px target reaches past it). |
--wm-video-player-scrubber-slot-coarse | 32px | The same, for a coarse pointer. |
--wm-video-player-come-duration | var(--md-sys-motion-duration-short-4) | How long the controls take to come (timed against the reference player). |
--wm-video-player-come-easing | var(--md-sys-motion-easing-standard-decelerate) | Their easing as they come. |
--wm-video-player-go-duration | var(--md-sys-motion-duration-short-2) | How long the controls take to go. |
--wm-video-player-go-easing | var(--md-sys-motion-easing-standard-accelerate) | Their easing as they go. |
--wm-video-player-fade-duration | var(--md-sys-motion-spring-effects-default-duration) | The poster’s fade as the first frame arrives, and the waiting mark’s. |
--wm-video-player-fade-easing | var(--md-sys-motion-spring-effects-default-easing) | Their easing. |
--wm-video-player-on-hover-opacity | 0.08 | The hover layer over a control that is on, over its 12% ground (16% fell to 2.6:1 pressed). |
--wm-video-player-volume-track-height | 2px | The volume’s line. |
--wm-video-player-volume-band | 20px | The volume slider’s band in the bar (its 48px target reaches past it). |
--wm-video-player-volume-thumb-size | 14px | The volume’s handle, always shown. |
--wm-video-player-volume-track-color | color-mix(in srgb, var(--md-sys-color-on-surface) 30%, transparent) | The volume’s line past the value. |
--wm-video-player-volume-open-width | 88px | The volume slider opened beside its button: a 64px line, 12px either side. |
--wm-video-player-mark-padding | 16px | The space round the mark a key leaves. |
--wm-video-player-mark-icon-size | 32px | The mark’s icon. |
--wm-video-player-captions-ground | color-mix(in srgb, var(--md-sys-color-scrim) 72%, transparent) | The ground behind the caption lines. |
--wm-video-player-captions-max-width | 40rem | The caption lines’ widest. |
--wm-video-player-captions-inset | 16px | The captions’ distance from the foot and the sides. |
--wm-video-player-captions-lift | 80px | How far the captions rise while the controls show. |
--wm-video-player-scrim-height | 32px | In the `scrim` look, how far the gradient reaches over the scrubber. |
--wm-video-player-scrim-bar-color | color-mix(in srgb, var(--md-sys-color-scrim) 80%, transparent) | The `scrim` look’s gradient at the foot, behind the bar. |
--wm-video-player-scrim-line-color | color-mix(in srgb, var(--md-sys-color-scrim) 64%, transparent) | The gradient at the scrubber’s line: no lighter than the containers’ 64%, so the time keeps 4.5:1 and an icon 3:1 over a white picture. |
--wm-video-player-idle-delay | 2600ms | A still pointer over a playing picture: the controls go after this. |
--wm-video-player-double-tap | 300ms | Two taps on the same side within this skip 10 seconds. |
--wm-video-player-mark-stay | 500ms | How long the mark a key leaves stays. |
--wm-video-player-waiting-delay | 500ms | The waiting mark shows once a wait has lasted this long, so a short one never flashes. |
--wm-video-player-play-delay | 400ms | For a player that starts by itself, Play in the middle waits this long, so it never flashes before the video starts. |
--wm-video-player-resumed-for | 8s | The “Resumed from” note goes once this much has played. |
| Variable | Default | Paints |
|---|---|---|
--wm-on-media-content-color | var(--md-sys-color-on-surface) | Icons and words over a picture: the dark scope’s light content colour. |
--wm-on-media-container-color | color-mix(in srgb, var(--md-sys-color-scrim) 64%, transparent) | A container’s see-through ground: the least that keeps an icon at 3:1 and a time at 4.5:1 over a white picture. |
--wm-on-media-container-fallback-color | var(--md-sys-color-surface-container-high) | The ground without a backdrop blur, or under reduced transparency: opaque by default. |
--wm-on-media-tooltip-color | var(--_wm-on-media-container-color) | A tooltip’s see-through ground over a picture (the video player’s time at the pointer): the containers’ by default. Keep it dark enough for the words to hold 4.5:1 over a white picture. |
--wm-on-media-blur | 12px | The blur behind a container (`0px` turns it off). |
--wm-on-media-corner | var(--md-sys-shape-corner-full) | A container’s corners. |
--wm-on-media-hover-opacity | 0.16 | The hover layer on a control over a picture (M3’s 8% is too faint there). |
--wm-on-media-focus-opacity | var(--md-sys-state-focus-state-layer-opacity) | The keyboard-focus layer on a control over a picture. |
--wm-on-media-pressed-opacity | var(--md-sys-state-pressed-state-layer-opacity) | The pressed layer and ripple on a control over a picture. |
--wm-on-media-focus-ring-color | var(--md-sys-color-on-surface) | The focus ring’s light band, on keyboard focus only. |
--wm-on-media-focus-ring-edge-color | var(--md-sys-color-scrim) | The dark edge either side of the light band, so the ring keeps 3:1 over a white picture and a black one. |
--wm-on-media-focus-ring-width | var(--md-sys-focus-indicator-thickness) | The light band’s width. |
--wm-on-media-focus-ring-offset | var(--md-sys-focus-indicator-offset) | The gap between the control and the light band, filled by the dark edge. |
| Variable | Default | Paints |
|---|---|---|
--wm-media-slider-track-height | 4px | The line’s thickness (a player’s volume sets 2px). |
--wm-media-slider-track-color | color-mix(in srgb, var(--md-sys-color-on-surface) 30%, transparent) | The line past the value. |
--wm-media-slider-played-color | var(--md-sys-color-on-surface) | The line up to the value. |
--wm-media-slider-thumb-size | 16px | The round handle’s diameter, always shown (a player’s volume sets 14px). |
--wm-media-slider-thumb-color | var(--md-sys-color-on-surface) | The handle. |