SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

VideoPlayer

A video player built on the browser's own <video>.

Centering 3 kgLesson 7 · 11:43
  1. Today it's three kilos, which changes how you sit.
  2. Squeeze from the base and let the clay rise into a cone.
  3. Now press it back down with the heel of your hand.
  4. Lock your elbow against your thigh; the wheel does the work.
  5. Rest one finger on the side. If it doesn't move, you're centred.
View code
tsx
<VideoPlayer duration={703} chapters={chapters} transcript={transcript}>
	<VideoPlayer.Screen label="Centering 3 kg" captionsLabel="English" chaptersLabel="Chapters">
		<VideoPlayer.Source src="/lesson-2160.webm" type="video/webm" label="2160p" badge="4K" />
		<VideoPlayer.Source src="/lesson-1080.webm" type="video/webm" label="1080p" badge="HD" />
		<VideoPlayer.Source src="/lesson.mp4" type="video/mp4" />
		<VideoPlayer.Controls label="Video controls">
			<VideoPlayer.Progress label="Seek" />
			<VideoPlayer.Play label="Play" pauseLabel="Pause" />
			<VideoPlayer.Time />
			<VideoPlayer.CaptionsToggle label="Subtitles/closed captions" />
			<VideoPlayer.Settings label="Settings">
				<VideoPlayer.SettingsToggle name="ambient" label="Ambient mode" checked />
				<VideoPlayer.CaptionsMenu label="Subtitles/CC" offLabel="Off" backLabel="Back" />
				<VideoPlayer.SettingsMenu name="sleep" label="Sleep timer" backLabel="Back">
					<VideoPlayer.SettingsOption value="off" checked>Off</VideoPlayer.SettingsOption>
					<VideoPlayer.SettingsOption value="15">15 minutes</VideoPlayer.SettingsOption>
					<VideoPlayer.SettingsOption value="end">End of video</VideoPlayer.SettingsOption>
				</VideoPlayer.SettingsMenu>
				<VideoPlayer.SpeedMenu label="Playback speed" normalLabel="Normal" backLabel="Back" />
				<VideoPlayer.QualityMenu label="Quality" backLabel="Back" />
			</VideoPlayer.Settings>
			<VideoPlayer.Theater label="Theater mode" />
			<VideoPlayer.Fullscreen label="Full screen" />
		</VideoPlayer.Controls>
	</VideoPlayer.Screen>
	<VideoPlayer.Scrubber />
	<VideoPlayer.Caption meta="Lesson 7 · 11:43">Centering 3 kg</VideoPlayer.Caption>
	<VideoPlayer.Side>
		<VideoPlayer.Chapters label="Chapters" />
		<VideoPlayer.Transcript label="Transcript" />
	</VideoPlayer.Side>
</VideoPlayer>

Installation

An ordinary dependency: install it, import the theme once, and import the component where it is used.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Usage

typescript
import { VideoPlayer } from "@sdxc/ui/video";

A <figure> sharing one timeline with its parts; with no script its native controls play and time links open the file there. Map VideoPlayerSync (@sdxc/ui/video/video-player) for the bar. Theming: --ui-video-player- radius, progress-color, menu-bg, on-video, transcript-height.

Composition

The parts the component publishes, each a static property of the host.

  • VideoPlayer
  • VideoPlayer.ScreenThe 16:9 screen: a native <video controls> holding its sources and the chapters and captions tracks written from the timeline, over a VideoPlayer.Frame when given, under a VideoPlayer.Controls bar that takes over from the native controls.
  • VideoPlayer.SourceOne file the video may play, in preference order, exactly as a <source> inside <video>; the first one also gives every time link its address.
  • VideoPlayer.FrameA drawn still under the video: it shows before playback and through any transparent part of the picture while it plays.
  • VideoPlayer.ScrubberThe chapters as one bar of segments as long as each chapter, filled to the current moment, so the video's shape shows before it plays.
  • VideoPlayer.CaptionThe video's title line: the title at the start, small print at the end, wrapping under each other on a narrow screen.
  • VideoPlayer.SideThe second column: chapters, transcript and anything the page adds, such as a card for the next video, stacked in order.
  • VideoPlayer.ChaptersThe chapters as links to their moments, each with its still when given; the chapter playing carries aria-current.
  • VideoPlayer.TranscriptThe transcript in a scroll region, each line behind a link to its moment; the line playing carries aria-current and the island keeps it in view.
  • VideoPlayer.ControlsThe custom control bar along the bottom of the screen, rendered hidden until the island swaps it for the native controls.
  • VideoPlayer.ProgressThe seek slider: a native range over the video's length, so arrow keys, Home and End seek and assistive technology reads the time.
  • VideoPlayer.PlayPlays and pauses; its accessible name says what a press does next.
  • VideoPlayer.TimeThe time played and the video's length, 1:12 / 11:43.
  • VideoPlayer.CaptionsToggleTurns captions on and off: on shows the track last chosen in the captions menu, the first one at the start.
  • VideoPlayer.SettingsThe settings gear and its menu: a Popover API surface the gear opens through commandfor, holding toggles and submenus in order.
  • VideoPlayer.SettingsToggleA page-defined switch row: a real checkbox the page reads by name and follows with an ordinary change listener, such as ambient mode or a voice boost.
  • VideoPlayer.SettingsMenuA page-defined submenu: a row naming the current choice that opens a panel of VideoPlayer.SettingsOption radios under one name, such as a sleep timer.
  • VideoPlayer.SettingsOptionOne choice of a VideoPlayer.SettingsMenu: a real radio under the menu's name, marked with a check when chosen.
  • VideoPlayer.CaptionsMenuThe captions submenu: Off, then every captions and subtitles track the video holds.
  • VideoPlayer.SpeedMenuThe playback speed submenu; a choice sets the video's playbackRate and survives a quality change.
  • VideoPlayer.QualityMenuThe quality submenu: one row per labelled VideoPlayer.Source, by its label and badge; an unlabelled source is a format fallback and stays off the menu.
  • VideoPlayer.TheaterTheater mode: sets data-theater on the player, which drops the side column under the screen so the video takes the full width.
  • VideoPlayer.FullscreenFull screen for the screen with its bar, so the controls stay.

Examples

tsx
<VideoPlayer duration={703} chapters={chapters} transcript={lines} tone="theater">
	<VideoPlayer.Screen label="Centering 3 kg" captionsLabel="English" chaptersLabel="Chapters">
		<VideoPlayer.Source src="/07.mp4" type="video/mp4" label="1080p" badge="HD" />
		<VideoPlayer.Controls label="Video controls"><VideoPlayer.Progress label="Seek" /><VideoPlayer.Play label="Play" pauseLabel="Pause" /><VideoPlayer.Time /></VideoPlayer.Controls>
	</VideoPlayer.Screen>
	<VideoPlayer.Side><VideoPlayer.Transcript label="Transcript" /></VideoPlayer.Side>
</VideoPlayer>

Props

Read from the component's own types, so every prop, every default and every allowed value is listed.

PropTypeRequiredDescription
durationnumberYesLength in seconds; it closes the last chapter and the last caption.
chaptersreadonly Chapter[]NoChapters in playing order.
transcriptreadonly Cue[]NoSpoken lines in playing order.
currentnumberNoThe moment the page renders as now, in seconds, before the island takes over.
tone"plain" | "theater"NoColour scheme of the player. @default "plain"
childrenRemixNodeYesThe parts, in reading order; a VideoPlayer.Side becomes the second column.

Also accepts everything in TagProps<"figure">.

VideoPlayer.Screen

PropTypeRequiredDescription
labelstringYesThe video's accessible name.
posterstringNoImage shown before playback, as the native poster.
languagestringNoLanguage of the chapters and captions tracks. @default "en"
captionsLabelstringYesThe captions track's name in the player's menus, such as "English".
chaptersLabelstringYesThe chapters track's name, such as "Chapters".
childrenRemixNodeYesVideoPlayer.Source elements in preference order, any extra <track>, an optional VideoPlayer.Frame and an optional VideoPlayer.Controls.

Also accepts everything in Omit<TagProps<"div">, "children">.

VideoPlayer.Source

PropTypeRequiredDescription
srcstringYesThe file's address; the first source's is where every time link points.
typestringNoMedia type, such as video/webm, so the browser skips files it cannot play.
labelstringNoThe file's name in the quality menu, such as 1080p; the file name stands in when unset.
badgestringNoShort mark beside the label and on the settings gear, such as HD or 4K.

Also accepts everything in Omit<TagProps<"source">, "children">.

VideoPlayer.Frame

VideoPlayer.Scrubber

VideoPlayer.Caption

PropTypeRequiredDescription
metaRemixNodeNoSmall print at the inline end, such as "Lesson 7 · 11:43".

Also accepts everything in TagProps<"figcaption">.

VideoPlayer.Side

VideoPlayer.Chapters

PropTypeRequiredDescription
labelstringYesThe visible label and the list's accessible name.

Also accepts everything in Omit<TagProps<"nav">, "children">.

VideoPlayer.Transcript

PropTypeRequiredDescription
labelstringYesThe visible label and the scroll region's accessible name.

Also accepts everything in Omit<TagProps<"div">, "children">.

VideoPlayer.Controls

PropTypeRequiredDescription
labelstringYesThe bar's accessible name, such as "Video controls".

Also accepts everything in TagProps<"div">.

VideoPlayer.Progress

PropTypeRequiredDescription
labelstringYesThe slider's accessible name, such as "Seek".

Also accepts everything in Omit< TagProps<"input">, "type" | "min" | "max" | "value" | "children" | "role" >.

VideoPlayer.Play

PropTypeRequiredDescription
pauseLabelstringYesThe name while the video plays; label is the name while it is paused.

Also accepts everything in ButtonProps.

VideoPlayer.Time

VideoPlayer.CaptionsToggle

VideoPlayer.Settings

PropTypeRequiredDescription
idstringNoThe menu's id, which the gear's commandfor names. Defaults to a generated one.
badgestring | falseNoMark on the gear. Left out, it is the playing source's badge and follows the quality menu; false draws none.
childrenRemixNodeYesRows of the menu, in order.

Also accepts everything in ButtonProps.

VideoPlayer.SettingsToggle

PropTypeRequiredDescription
namestringYesThe form name a change listener reads the switch by.
labelRemixNodeYesThe row's visible label.

Also accepts everything in Omit< TagProps<"input">, "type" | "name" | "children" >.

VideoPlayer.SettingsMenu

PropTypeRequiredDescription
namestringYesThe radio group's form name, which a change listener reads the choice by.
labelRemixNodeYesThe row's visible label, repeated on the submenu's back row.
backLabelstringYesThe back row's accessible prefix, such as "Back".
childrenRemixNodeYesVideoPlayer.SettingsOption elements; the one marked checked is chosen.

Also accepts everything in Omit<TagProps<"div">, "children">.

VideoPlayer.SettingsOption

PropTypeRequiredDescription
valuestringYesThe value a change listener reads from the menu's name once this is chosen.
badgeRemixNodeNoA short mark after the label, such as 4K.
childrenRemixNodeYesThe option's visible label, which its submenu's row repeats once chosen.

Also accepts everything in Omit< TagProps<"input">, "type" | "name" | "children" | "value" >.

VideoPlayer.CaptionsMenu

PropTypeRequiredDescription
offLabelstringYesThe option that hides every track, such as "Off".

Also accepts everything in BuiltInMenuProps.

VideoPlayer.SpeedMenu

PropTypeRequiredDescription
ratesreadonly number[]NoRates offered, in order. @default [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2]
normalLabelstringYesThe name of rate 1, such as "Normal".

Also accepts everything in BuiltInMenuProps.

VideoPlayer.QualityMenu

VideoPlayer.Theater

VideoPlayer.Fullscreen

Types

NameValuesWhat it decides
Tone"plain" | "theater"plain follows the page's scheme; theater is a dark screening room in either.
@sdxc/ui

Can’t find it? Contact us