Skip to content

Media time slider

Pro

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

import { MediaTimeSlider } 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

The position bar of a video or audio player: where playback is, how much has loaded, and a way to move through it by pointer, touch and keyboard. It is a slider in seconds, named after the part the leading web players call a time slider.

M3 has no media components, and its Slider is a form control with tracks from 16px, so this one follows M3's colour roles, shapes and springs instead of a spec. To choose a number or a volume, use a Slider; for progress the person can't move, a Progress indicator.

Behaviour

  • A 4px bar that grows to 8px, showing its handle, under the pointer, while dragged or keyboard-focused. The played part is primary; the loaded parts sit behind it.
  • duration, value and buffered are in seconds. buffered takes an end time (loaded from the start), [start, end] ranges, or a media element's buffered as it is.
  • onChange follows every move of a drag; onChangeEnd comes when the drag ends or a key moves it: the moment to seek. While dragged, and after a seek until value lands within a second of where it was put (two seconds at most, for a seek the player refused), it shows where it was put, so the player's time updates neither fight a drag nor pull the handle back before the seek lands. A known length that changes (a stream growing) lets a held seek go, never a drag, and so does a form reset. A new media's length is unknown while it loads, which lets go of everything held for the last one, a drag included: pass the media element's duration as it is, and keep the slider mounted rather than giving it a new key, which would drop focus on it to the page.
  • A screen reader's step (one step of the native input, such as a swipe up or down on a phone's screen reader) moves step seconds and seeks, as a key does. While the slider has focus, the value screen readers read stays where the person last put it, so playback doesn't make it speak every second; it refreshes on each key, step or drag, and follows playback again once focus leaves. The handle on screen keeps moving.
  • A bubble shows the time under the pointer before a press, and the handle's time while it moves or has keyboard focus. It is m:ss, or h:mm:ss for an hour or longer; formatTime writes your own. It shows above the bar, outside the slider's box, so leave about 40px above it.
  • Under a mouse, a trackpad or a pen (never a touch), the stretch from the played part to the pointer fills, where a press would land: its own token, --wm-media-time-slider-hover-color, primary at 38% by default (transparent turns it off). Forced colours hide it. --wm-media-time-slider-thumb-size-rest keeps a dot at rest (none by default), so a paused player shows where it is.
  • The bar runs left to right in every language, as media progress does: on a right-to-left page it fills from the left, Arrow Right moves forward and the pointer reads from the left. Its times and words stay in the page's locale and digits (Arabic-Indic digits in ar-EG). Only its parts run left to right: the root keeps the page's direction, so your logical classes on it (ms-4) stay on the page's side.
  • chapters, each a start in seconds and a title, split the bar by --wm-media-time-slider-chapter-gap; the segment under the pointer or the handle grows a step, and the bubble shows its title over the time, said with the position too. --wm-media-time-slider-played-color-end turns the played part into a gradient across the played length, and --wm-media-time-slider-underlay-color draws a ground under the line only, for contrast over a picture (the VideoPlayer sets it).
  • A touch waits to tell a tap, a drag and a scroll apart, as the core Slider does: a tap seeks as the finger lifts, a drag starts after 8px along the bar, and a swipe across it scrolls the page.
  • Until the length is known (duration 0 or NaN, as a media element's before its metadata loads), and with Infinity, a live stream's, it can't be moved: it is marked aria-disabled, reads labels.unknownLength and leaves the Tab order, but focus already on it stays as the next media loads. disabled turns it off fully.

When not to use

For choosing a number, or a volume, use a Slider; for progress the person can't move, a Progress indicator.

See also

  • Slider: Chooses a value or a range on a continuous or stepped scale, in five sizes.
  • Media viewer: A full-screen viewer for a set of photos: swipe between them, zoom, and read each caption and position. Not an M3 component (@windmorph/react-pro).
  • Progress indicators: Linear and circular indicators, determinate or indeterminate, flat or wavy.