UIComponentsReact
Controls for the page's own `<video>` or `<audio>`: play and pause, skip back and forward, a seek bar with the buffered range, the time, mute and volume, captions, picture-in-picture and fullscreen.
Built on the headless Media Player.See its API in Docs
Rendered by React 19.3.1
Installation
npx shadcn@4.23.0 add https://hamur.dev/r/react/media-player.jsonIt also adds utils, button. The app needs its setup first: Installation.
Usage
Put a MediaPlayerMedia and a MediaPlayerControls inside MediaPlayer, and the controls inside the Controls. MediaPlayerMedia is a <video> that takes the source, the <track> elements and every attribute as written; render with an <audio> plays audio, and the Controls then stand under it instead of over the picture. The seek bar is MediaPlayerSeek with a MediaPlayerSeekControl around a MediaPlayerSeekTrack (holding MediaPlayerSeekBuffered and MediaPlayerSeekIndicator) and a MediaPlayerSeekThumb; the volume is MediaPlayerVolume with the same four parts. MediaPlayerSeekButton skips by amount seconds, back when it is negative. MediaPlayerTime shows the current time, type="duration" the duration and type="remaining" the time left. MediaPlayerError shows only while the media has an error. With focus inside the player, Space and k play and pause, the arrow keys seek and change the volume, m mutes, c toggles captions and f fullscreen. volume, muted, playbackRate, textTrack, defaultCurrentTime, seekStep, volumeStep, keyboardShortcuts, idleTimeout, disabled, labels, actionsRef and the change callbacks come from the headless Media Player.
import {
MediaPlayer,
MediaPlayerCaptionsButton,
MediaPlayerControls,
MediaPlayerError,
MediaPlayerFullscreenButton,
MediaPlayerMedia,
MediaPlayerMuteButton,
MediaPlayerPictureInPictureButton,
MediaPlayerPlayButton,
MediaPlayerSeek,
MediaPlayerSeekBuffered,
MediaPlayerSeekButton,
MediaPlayerSeekControl,
MediaPlayerSeekIndicator,
MediaPlayerSeekThumb,
MediaPlayerSeekTrack,
MediaPlayerTime,
MediaPlayerVolume,
MediaPlayerVolumeControl,
MediaPlayerVolumeIndicator,
MediaPlayerVolumeThumb,
MediaPlayerVolumeTrack,
} from '@/components/ui/media-player'Examples
Default
A video with captions and every control: play, skip, the seek bar, the time, volume, captions, picture-in-picture and fullscreen.
The player is dark in both themes, with rounded corners, and the video fills its width at 16:9. Over a video the Controls lie on a gradient along the bottom edge and fade out (opacity only) while the media plays and the pointer rests; a pointer move, a key or keyboard focus inside brings them back. The buttons are the Button's ghost icon-sm, 32 by 32 CSS pixels (WCAG 2.5.8), with a focus ring (WCAG 2.4.7); their lucide icons are hidden from assistive technology, so each is named by labels and the name says what a press does ("Play", "Mute", "Show captions"). Play and Pause, Volume and Muted, and the two fullscreen icons are picked with CSS on the button's own state; Captions and picture-in-picture take a lighter background while on. A button whose feature the browser or the media lacks is hidden. The seek bar spans the Controls, its buffered range lighter than the played one; the Volume is 80 CSS pixels wide. The duration, or the time remaining, pushes the buttons after it to the end of the row. The Error covers the picture with its message. Give each <track> an id, kind, srclang and label, and do not autoplay with sound. This item takes Base UI's component ID as its slug and one name per Base UI part.
API reference
The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Media Player's API reference.