Skip to content

Video player

Pro

A 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

By name or description, across the 116 props below

VideoPlayer 67 props

  • sourcetype VideoSourceRequired

    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.

  • postertype VideoPlayerPoster

    The picture shown until the first frame.

  • posterLoadingtype "eager" | "lazy"default "lazy"

    How the poster loads: eager for a page's main image.

  • posterDelaytype numberdefault 0

    Holds the poster back this many ms where this player follows another (a feed's next video), so it never flashes between the two.

  • durationtype number

    The video's length in seconds, if known before anything loads, so the time shows at first paint.

  • widthtype number

    The video's width, if known before anything loads: its shape turns and fits the picture.

  • heighttype number

    The video's height, likewise.

  • chapterstype readonly MediaTimeSliderChapter[]

    The video's chapters, drawn on the scrubber.

  • autoPlaytype booleandefault false

    Starts playing when it shows (muted, where the browser insists).

  • volumetype number

    The volume, 0 to 1 (controlled).

  • defaultVolumetype numberdefault 1

    The volume at first (uncontrolled).

  • mutedtype boolean

    Whether the sound is off (controlled). A mute the browser forced on a video that started by itself is never reported.

  • defaultMutedtype booleandefault false

    The sound off at first (uncontrolled).

  • playerReftype Ref<VideoPlayerHandle>

    The player's actions for an app outside it: play, pause, seek(seconds), toggleFullScreen and togglePictureInPicture (the last two only inside a press or key handler, which the browser asks for).

  • playbackRatetype number

    The speed (controlled).

  • defaultPlaybackRatetype numberdefault 1

    The speed at first (uncontrolled).

  • playbackRatestype readonly number[]default quarters from 0.25 to 2

    The speeds < and > step through.

  • playbackRatePresetstype readonly (number | VideoPlayerSettingsSpeedPreset)[]default 1, 1.25, 1.5 and 2, those within playbackRates

    The settings' Playback speed presets, a press away (VideoPlayerSettingsSpeed's presets): speeds that fit the app's fastest one, a locked speed. The page's slider runs from the slowest to the fastest of playbackRates.

  • looptype boolean

    Plays again from the start when it ends (controlled).

  • defaultLooptype booleandefault false

    Loops at first (uncontrolled).

  • rotatabletype booleandefault false

    Offers Rotate: the button (fine pointers, from a 42rem player) and R and Shift+R.

  • rotationtype number

    The picture's turn in degrees, a multiple of 90 (controlled).

  • defaultRotationtype numberdefault 0

    The turn at first (uncontrolled).

  • autoplayNexttype boolean

    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 onAutoplayNextChange is given.

  • defaultAutoplayNexttype booleandefault false

    Autoplay at first (uncontrolled).

  • theatertype boolean

    Theater mode (controlled): the player holds and reports it (data-theater); the page's layout is the app's. The button and T show once onTheaterChange is given.

  • defaultTheatertype booleandefault false

    Theater at first (uncontrolled).

  • theaterFromtype "medium" | "expanded" | "large"default "expanded"

    The smallest window size class with the theater button and T.

  • captionstype readonly VideoPlayerCaptionTrack[]

    The caption tracks: with any, a Captions button and C. The player draws them itself.

  • captionsLangtype string | null

    The language whose captions show, null for none (controlled).

  • defaultCaptionsLangtype string | nulldefault null

    Captions at first (uncontrolled).

  • resumeFromtype number

    Starts at this second, saying "Resumed from 12:34" with Start over until 8 seconds have played.

  • inViewtype "pause" | "play"default none (neither)

    For a player in a feed: pause pauses it whenever less than 60% of it is in view or covered, however it was started; play also 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.

  • coveredtype boolean

    Something lies over the player (a sheet, a dialog): with inView, it pauses.

  • looktype "grouped" | "scrim"default "grouped"

    The bar's look: grouped, each control or group in its own see-through container (the default), or scrim, bare controls over a dark gradient at the foot.

  • controlstype ReactNode

    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 a toggle), after Theater mode and Picture-in-picture and before Next; its key still works. Anything else here stays on the bar.

  • settingstype ReactNode

    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.

  • settingsBadgetype ReactNode

    A mark on the Settings button's icon (a quality tag), upright while the gear turns, hidden from assistive tech.

  • endedtype ReactNode

    Over the picture when the video ends, in place of Replay there.

  • iconstype VideoPlayerIcons

    Replaces the player's icons.

  • videoReftype Ref<HTMLVideoElement>

    The <video> element, for the app (a glow behind the player, say).

  • videoPropstype Omit<VideoHTMLAttributes<HTMLVideoElement>, "src" | "controls" | "autoPlay">

    Other attributes for the <video> (crossOrigin, say).

  • reftype Ref<HTMLDivElement>

    Ref to the frame.

  • idtype string

    The frame's id.

Events

  • onPlaytype (() => void)

    Called as playback starts.

  • onPausetype (() => void)

    Called as playback pauses.

  • onEndedtype (() => void)

    Called as the video ends.

  • onTimeUpdatetype ((seconds: number) => void)

    Called as the time moves, in seconds.

  • onErrortype ((error: MediaError | null) => void)

    Called when the video can't load.

  • onFullScreenChangetype ((fullScreen: boolean) => void)

    Called as the player enters or leaves full screen.

  • onVolumeChangetype ((volume: number) => void)

    Called when the person changes the volume.

  • onMutedChangetype ((muted: boolean) => void)

    Called when the person mutes or unmutes.

  • onPlaybackRateChangetype ((rate: number) => void)

    Called when the speed changes.

  • onPlaybackRatePresetPresstype ((preset: VideoPlayerSettingsSpeedPreset) => void)

    Called when a speed preset is pressed, a disabled one included (a locked speed).

  • onLoopChangetype ((loop: boolean) => void)

    Called when Loop is switched.

  • onNexttype (() => void)

    Given, a Next button joins Play's container, with Shift+N.

  • onRotationChangetype ((degrees: number) => void)

    Called when the picture turns.

  • onAutoplayNextChangetype ((autoplay: boolean) => void)

    Called when Autoplay is switched.

  • onTheaterChangetype ((theater: boolean) => void)

    Called when theater is switched.

  • onCaptionsLangChangetype ((lang: string | null) => void)

    Called when captions come on, change or go off.

  • onPictureInPictureChangetype ((active: boolean) => void)

    Called as the video enters or leaves picture-in-picture.

Text

  • labelstype Partial<VideoPlayerLabels>

    Words the player says, with English defaults. A LabelsProvider sets them for the whole app.

  • aria-labeltype string

    One of aria-label or aria-labelledby is required.

  • aria-labelledbytype string

    One of aria-label or aria-labelledby is required.

VideoPlayerControl 16 props

  • labeltype stringRequired

    Its name.

  • icontype ReactElement<unknown, string | JSXElementConstructor<any>>Required

    Its icon.

  • tiptype stringdefault label

    Its tooltip, when it says more than the name (a state).

  • shortcuttype string

    Its key (S, Shift+S), shown in the tooltip, given as aria-keyshortcuts and bound while focus is in the player: it presses the control, or switches it. The player's own keys win.

  • selectedIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    The icon while on, for an on and off control.

  • badgetype ReactNode

    A mark on the icon's top end corner (a quality tag), inside the button, upright, hidden from assistive tech.

  • toggletype boolean

    An on and off control: aria-pressed, a filled icon on a ground while on.

  • selectedtype boolean

    Whether it is on (controlled).

  • defaultSelectedtype booleandefault false

    Whether it starts on (uncontrolled).

  • disabledtype boolean

    Can't be pressed.

  • reftype Ref<HTMLButtonElement>

    Ref to the button.

  • idtype string

    The button's id.

Events

  • onSelectedChangetype ((selected: boolean) => void)

    Called when it is switched.

  • onPresstype (() => void)

    Called when it is pressed.

VideoPlayerControlGroup 5 props

  • childrentype ReactNodeRequired

    The controls it holds.

  • reftype Ref<HTMLDivElement>

    Ref to the container.

  • idtype string

    The container's id.

VideoPlayerVolume 4 props

  • reftype Ref<HTMLDivElement>

    Ref to its container.

  • idtype string

    Its container's id.

VideoPlayerNotice 7 props

  • childrentype ReactNodeRequired

    What it says.

  • icontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Its icon, 32px.

  • actiontype { label: string; onPress: () => void; }

    A text button under it ("Try again").

  • reftype Ref<HTMLDivElement>

    Ref to the notice.

  • idtype string

    The notice's id.

MediaSlider 17 props

  • valuetype number

    The value (controlled).

  • defaultValuetype numberdefault min

    The value at first (uncontrolled).

  • mintype numberdefault 0

    The smallest value.

  • maxtype numberdefault 1

    The largest value.

  • steptype numberdefault 0.05

    One step: an arrow key's move.

  • pageSteptype numberdefault four steps

    A larger step: Page Up and Page Down.

  • valueTexttype ((value: number) => string)

    The value in words for screen readers (aria-valuetext), "Volume 55%" or "1.5×".

  • disabledtype booleandefault false

    Can't be moved or focused.

  • idtype string

    The root's id.

  • reftype Ref<HTMLDivElement>

    The root element.

Events

  • onChangetype ((value: number) => void)

    Called as the value moves.

  • onChangeEndtype ((value: number) => void)

    Called once a move ends (a drag let go, a key).

Text

  • aria-labeltype string

    One of aria-label or aria-labelledby is required.

  • aria-labelledbytype string

    One of aria-label or aria-labelledby is required.

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.

  • srctype stringRequired
  • srcSettype string
  • sizestype string

VideoPlayerCaptionTrack 3 fields

A caption track the app gives the player.

  • langtype stringRequired

    Its language, a BCP 47 code ("en", "fr-CA"): its name is said in the reader's language.

  • srctype stringRequired

    The WebVTT file.

  • labeltype string

    Its name, where the language's name isn't enough ("English, with descriptions").

Hooks

useVideoPlayer

useVideoPlayer signature
useVideoPlayer(): VideoPlayerState

Inside a VideoPlayer: its state and actions.

Returns VideoPlayerState

  • playingtype booleanRequired
  • endedtype booleanRequired
  • timetype numberRequired
  • durationtype numberRequired
  • mutedtype booleanRequired
  • volumetype numberRequired
  • fullScreentype booleanRequired
  • playtype () => voidRequired
  • pausetype () => voidRequired
  • seektype (seconds: number) => voidRequired
  • setMutedtype (muted: boolean) => voidRequired
  • setVolumetype (volume: number) => voidRequired
  • ratetype numberRequired

    The speed, and the speeds offered.

  • ratestype readonly number[]Required
  • setRatetype (rate: number) => voidRequired
  • looptype booleanRequired
  • setLooptype (loop: boolean) => voidRequired
  • rotationtype numberRequired

    The picture's turn, in degrees.

  • rotatabletype booleanRequired
  • rotatetype (by: 90 | -90) => voidRequired
  • autoplayNexttype booleanRequired

    Autoplay's state, and whether the app offers it.

  • autoplayOfferedtype booleanRequired
  • setAutoplayNexttype (autoplay: boolean) => voidRequired
  • bufferedtype TimeRanges | nullRequired

    What has loaded, as the element reports it.

  • captionstype readonly VideoPlayerCaptionTrack[]Required

    The caption tracks, the one showing (null for none), and the way to choose one.

  • captionsLangtype string | nullRequired
  • setCaptionsLangtype (lang: string | null) => voidRequired
  • theatertype booleanRequired

    Theater mode, and whether the app offers it.

  • theaterOfferedtype booleanRequired
  • setTheatertype (theater: boolean) => voidRequired
  • toggleFullScreentype () => voidRequired

    Enters or leaves full screen (only inside a press or key handler).

  • pictureInPicturetype booleanRequired

    Picture-in-picture: whether it's on, whether the browser has it, and the way in and out.

  • pictureInPictureAvailabletype booleanRequired
  • togglePictureInPicturetype () => voidRequired
  • widthClasstype "compact" | "medium" | "expanded"Required

    The player's width class, by its own width: compact under 30rem (round buttons, no volume slider), medium under 42rem (Autoplay and Rotate in the settings), expanded from 42rem. compact until 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.

  • 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.

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.

VideoPlayer tokens
VariableDefaultPaints
--wm-video-player-inset-inline12pxThe controls’ distance from the player’s sides (the scrubber’s too).
--wm-video-player-inset-bottom8pxThe controls’ distance from the player’s foot.
--wm-video-player-container-height40pxA container’s height: 4px round 32px buttons.
--wm-video-player-container-padding4pxThe space inside a container, round its buttons.
--wm-video-player-container-gap8pxThe space between containers.
--wm-video-player-button-gap2pxThe space between the buttons in one container.
--wm-video-player-icon-size24pxA bar button’s icon, in its 32px button (M3’s extra-small icon is 20px).
--wm-video-player-grouped-button-width48pxA button in a shared container, from a 30rem player (round below).
--wm-video-player-time-padding12pxThe time’s side padding in its container.
--wm-video-player-time-padding-wide16pxThe same, from a 30rem player.
--wm-video-player-on-groundcolor-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-groundcolor-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-groundcolor-mix(in srgb, var(--md-sys-color-scrim) 72%, transparent)The ground of a notice over the picture (failed, offline).
--wm-video-player-scrubber-gap4pxThe space between the scrubber’s slot and the containers.
--wm-video-player-scrubber-slot20pxThe scrubber’s slot over the containers (its 48px target reaches past it).
--wm-video-player-scrubber-slot-coarse32pxThe same, for a coarse pointer.
--wm-video-player-come-durationvar(--md-sys-motion-duration-short-4)How long the controls take to come (timed against the reference player).
--wm-video-player-come-easingvar(--md-sys-motion-easing-standard-decelerate)Their easing as they come.
--wm-video-player-go-durationvar(--md-sys-motion-duration-short-2)How long the controls take to go.
--wm-video-player-go-easingvar(--md-sys-motion-easing-standard-accelerate)Their easing as they go.
--wm-video-player-fade-durationvar(--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-easingvar(--md-sys-motion-spring-effects-default-easing)Their easing.
--wm-video-player-on-hover-opacity0.08The hover layer over a control that is on, over its 12% ground (16% fell to 2.6:1 pressed).
--wm-video-player-volume-track-height2pxThe volume’s line.
--wm-video-player-volume-band20pxThe volume slider’s band in the bar (its 48px target reaches past it).
--wm-video-player-volume-thumb-size14pxThe volume’s handle, always shown.
--wm-video-player-volume-track-colorcolor-mix(in srgb, var(--md-sys-color-on-surface) 30%, transparent)The volume’s line past the value.
--wm-video-player-volume-open-width88pxThe volume slider opened beside its button: a 64px line, 12px either side.
--wm-video-player-mark-padding16pxThe space round the mark a key leaves.
--wm-video-player-mark-icon-size32pxThe mark’s icon.
--wm-video-player-captions-groundcolor-mix(in srgb, var(--md-sys-color-scrim) 72%, transparent)The ground behind the caption lines.
--wm-video-player-captions-max-width40remThe caption lines’ widest.
--wm-video-player-captions-inset16pxThe captions’ distance from the foot and the sides.
--wm-video-player-captions-lift80pxHow far the captions rise while the controls show.
--wm-video-player-scrim-height32pxIn the `scrim` look, how far the gradient reaches over the scrubber.
--wm-video-player-scrim-bar-colorcolor-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-colorcolor-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-delay2600msA still pointer over a playing picture: the controls go after this.
--wm-video-player-double-tap300msTwo taps on the same side within this skip 10 seconds.
--wm-video-player-mark-stay500msHow long the mark a key leaves stays.
--wm-video-player-waiting-delay500msThe waiting mark shows once a wait has lasted this long, so a short one never flashes.
--wm-video-player-play-delay400msFor 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-for8sThe “Resumed from” note goes once this much has played.
On-media tokens (shared)
VariableDefaultPaints
--wm-on-media-content-colorvar(--md-sys-color-on-surface)Icons and words over a picture: the dark scope’s light content colour.
--wm-on-media-container-colorcolor-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-colorvar(--md-sys-color-surface-container-high)The ground without a backdrop blur, or under reduced transparency: opaque by default.
--wm-on-media-tooltip-colorvar(--_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-blur12pxThe blur behind a container (`0px` turns it off).
--wm-on-media-cornervar(--md-sys-shape-corner-full)A container’s corners.
--wm-on-media-hover-opacity0.16The hover layer on a control over a picture (M3’s 8% is too faint there).
--wm-on-media-focus-opacityvar(--md-sys-state-focus-state-layer-opacity)The keyboard-focus layer on a control over a picture.
--wm-on-media-pressed-opacityvar(--md-sys-state-pressed-state-layer-opacity)The pressed layer and ripple on a control over a picture.
--wm-on-media-focus-ring-colorvar(--md-sys-color-on-surface)The focus ring’s light band, on keyboard focus only.
--wm-on-media-focus-ring-edge-colorvar(--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-widthvar(--md-sys-focus-indicator-thickness)The light band’s width.
--wm-on-media-focus-ring-offsetvar(--md-sys-focus-indicator-offset)The gap between the control and the light band, filled by the dark edge.
MediaSlider tokens
VariableDefaultPaints
--wm-media-slider-track-height4pxThe line’s thickness (a player’s volume sets 2px).
--wm-media-slider-track-colorcolor-mix(in srgb, var(--md-sys-color-on-surface) 30%, transparent)The line past the value.
--wm-media-slider-played-colorvar(--md-sys-color-on-surface)The line up to the value.
--wm-media-slider-thumb-size16pxThe round handle’s diameter, always shown (a player’s volume sets 14px).
--wm-media-slider-thumb-colorvar(--md-sys-color-on-surface)The handle.