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.
Purpose
A video player that is complete with nothing set: its own controls, keys, touch gestures and states, over any <video>, a plain file or a stream an engine drives. It is drawn in the theme's colour roles, shapes, type and springs, built from the core's icon buttons, tooltips and loading indicator and Pro's MediaTimeSlider.
M3 has no video player. For a scrubber alone (an audio player of your own), use the MediaTimeSlider; for a video's length on a card, the DurationTag.
States
- Before anything is asked for, the poster shows with Play in the middle, and nothing of the video is downloaded: the source is set on the
<video>only when Play is first pressed.posterLoading="eager"loads a page's main poster at once. - Loading and buffering keep the picture and show the waiting mark after 500ms. Paused, the controls stay; playing, they go after 2.6 seconds without the pointer moving.
- Ended shows Replay in the middle and on the bar, or your
endedcontent in the middle with Replay on the bar. - Failed shows “Couldn't load video” with Try again, which reloads and plays from the same place. Offline while buffering, it says so and carries on when the connection is back. Both are said at once.
- Where the browser won't start a video with sound by itself, it starts muted with “Turn sound on” at the top start. Given
resumeFrom, it starts there and says “Resumed from 12:34” with Start over, until 8 seconds have played. - One video plays at a time on a page: starting one pauses the one before. A new source (another quality) keeps the place, the speed, the playing and the last frame.
- The root carries
data-state(poster,loading,buffering,playing,paused,ended,failed,offline),data-controls-shown,data-look,data-theater,data-fullscreen,data-pipanddata-settings-open.
Pointer and touch
- The controls come when the pointer moves over the picture and go when it leaves; they stay while keyboard focus is among them, while the settings are open, while the scrubber or the volume is dragged, and while the video isn't playing. Hidden, they stay in the tab order, and focus arriving by keyboard shows them.
- A mouse click on the picture plays or pauses; a double click toggles full screen.
- A tap shows the controls, or hides them over a playing video. Two taps within 300ms on the left third go back 10 seconds, on the right third forward 10.
- Full screen takes the whole frame, controls and captions included; a phone without element full screen uses the video's own player. Picture-in-picture shows where the browser has it, from a 30rem player. A button the browser can't do keeps its place, invisible, so nothing under the pointer moves.
Options
captions(WebVTT tracks): a Captions button and C. The player draws the lines itself, as plain text (cue markup is stripped), and names each track in the reader's language from its code. C turns on the track last chosen, then the page's language, then the first. In picture-in-picture and a phone's own full screen the browser draws the chosen track.chapterssplit the scrubber, each segment's title in the bubble over the time.onNextadds Next beside Play (Shift+N);rotatableadds Rotate (R, Shift+R back), turning only the picture a quarter at a time and saying the turn (“Rotated 90°”, “Upright”) from the key, the button or the settings' row alike;onAutoplayNextChangeadds the Autoplay switch, which the player only shows and reports;onTheaterChangeadds Theater (T) fromtheaterFrom, with the page's layout left to you.playbackRatesare the speeds < and > step through,loopthe<video>'s own loop. Every state takes the controlled and uncontrolled pair (loop,defaultLoop,onLoopChange),volumeandmutedtoo; a mute the browser forced is never reported as the person's.playbackRatePresetsare the speeds a press away on the settings' Playback speed page (1, 1.25, 1.5 and 2 by default, those withinplaybackRates), whose slider runs from the slowest to the fastest ofplaybackRates. A preset can carry a caption, a mark before its figure, or be disabled: a locked speed changes nothing and callsonPlaybackRatePresetPress, which every preset press calls.playerRefhands you aVideoPlayerHandlewithplay,pause,seek(seconds),toggleFullScreenandtogglePictureInPicture(the last two only inside a press or key handler).posterDelayholds the poster back where a player follows another, so it never flashes between the two.settingstakes aVideoPlayerSettings: a Settings button joins the bar after Captions, and its panel opens over the picture. On a narrow player, Autoplay and Rotate move from the bar into it.- The bar never runs past the player. Under the width its controls need it folds them into Settings, least important first (Rotate, Autoplay, Theater mode, Picture-in-picture, your own
controls, Next, Captions, Mute, then the time), keeping Play, Settings and Full screen to the last, so every control stays reachable down to 160px. A folded control is a row with the same state, words and keys; a Settings button shows whenever something is folded, with only the folded rows when you gave nosettings. inView, for a feed:pausepauses it when less than 60% is in view orcovered;playalso starts it, muted, while in view (never under reduced motion, nor after the person paused it).look="scrim"draws bare controls over a gradient at the foot, in place of a see-through container per group (grouped, the default).
The source
source is a URL the browser plays itself, or an engine's { attach(video) } returning what detaches it, called at the moment playback is first asked for. The player reads only the media element's standard state and events, so any streaming library fits behind attach, and none is a dependency. videoRef hands you the element, and videoProps passes attributes such as crossOrigin.
Parts
VideoPlayerControl: a button on the bar in the player's look, with a tooltip above it;shortcutshows a key in the tooltip and gives it asaria-keyshortcuts;togglemakes it an on and off control (selected,onSelectedChange,selectedIcon,defaultSelected);badgeputs a mark over its icon, hidden from assistive tech. Its shortcut works while focus is anywhere in the player. Pass yours incontrols.VideoPlayerControlGroup, a see-through container of controls;VideoPlayerVolume, the mute button with its thin slider; andVideoPlayerNotice, a notice over the frame, also for a frame shown without a player (“Still processing”).useVideoPlayer(), inside the player: its state (playing, time, length, what has loaded, volume, speed, loop, rotation, Autoplay, captions, theater, full screen, picture-in-picture, and its width class:compactunder 30rem,mediumto 42rem,expandedbeyond) and actions (play,pause,seek,setVolume,setRate…), for a control of your own.MediaSlider: the thin value slider the volume and the settings' speed use, in the same look as the scrubber, for a value of your own over a picture.
When not to use
For a position bar alone, in an audio player of your own, use the Media time slider; for a video's length on a card, a Duration tag.
See also
- Video player settings: A video player's settings: a small panel over the picture at the player's corner whose rows open pages in its place (speed, captions, quality), a bottom sheet on phones. Not an M3 component (@windmorph/react-pro).
- Media time slider: A media player's position bar: where playback is, what has loaded, and the time under the pointer, to seek by pointer, touch and keyboard. Not an M3 component (@windmorph/react-pro).
- Duration tag: A video's length in the corner of its picture, light on a dark see-through ground over any picture, read in words as part of the card's link. Not an M3 component (@windmorph/react-pro).