MediaPlayer

Composable audio and video player primitives built on Media Chrome.

Quick Preview

0:00 / 0:00

Usage

import {
	MediaPlayer,
	MediaPlayerControls,
	MediaPlayerControlsOverlay,
	MediaPlayerError,
	MediaPlayerFullscreen,
	MediaPlayerPiP,
	MediaPlayerPlay,
	MediaPlayerPlaybackSpeed,
	MediaPlayerSeek,
	MediaPlayerSeekBackward,
	MediaPlayerSeekForward,
	MediaPlayerTime,
	MediaPlayerVideo,
	MediaPlayerVolume,
} from "@giddaa-housing/ui/media-player";

<MediaPlayer>
	<MediaPlayerVideo>
		<source src="/assets/cloud.mp4" type="video/mp4" />
	</MediaPlayerVideo>
	<MediaPlayerError />
	<MediaPlayerControls className="flex-col items-start gap-2.5">
		<MediaPlayerControlsOverlay />
		<MediaPlayerSeek />
		<div className="flex w-full items-center gap-2">
			<div className="flex flex-1 items-center gap-2">
				<MediaPlayerPlay />
				<MediaPlayerSeekBackward />
				<MediaPlayerSeekForward />
				<MediaPlayerVolume expandable />
				<MediaPlayerTime />
			</div>
			<div className="flex items-center gap-2">
				<MediaPlayerPlaybackSpeed />
				<MediaPlayerPiP />
				<MediaPlayerFullscreen />
			</div>
		</div>
	</MediaPlayerControls>
</MediaPlayer>;

Examples

Captions, Chapters, and Settings

Add <track> elements to the video for captions and chapters. MediaPlayerCaptions toggles captions on and off, and MediaPlayerSettings opens a menu with playback speed and caption language submenus. Chapter cues split the timeline into segments and label the seek preview.

0:00 / 0:00

Error State

MediaPlayerError overlays the player when the media fails to load, with retry and reload actions.

0:00 / 0:00

Audio

Use MediaPlayerAudio with the same control primitives for audio-only layouts.

Minimal Audio

Compose a smaller player by changing the root and controls classes.

0:00 / 0:00

Behavior

  • Controls fade out after 2.5 seconds of inactivity while video plays, and reappear on pointer movement, keyboard focus, or pause. Audio players keep controls visible.
  • Dragging the timeline scrubs smoothly: the thumb follows the pointer, seeks are throttled to animation frames, and the position holds until the media catches up.
  • Hovering the timeline shows the target time, plus a thumbnail when the media provides a preview (storyboard) track and a chapter title when chapters exist.
  • The timeline shows buffered ranges as a lighter strip behind the progress bar.

Keyboard Shortcuts

Shortcuts work while focus is inside the player.

KeyAction
Space / KToggle play/pause
MToggle mute
FToggle fullscreen
CToggle captions
/ Seek back / forward 5 seconds

Props

Prop/APITypeDefaultDescription
MediaPlayerMedia Chrome controller props-Root controller that coordinates media state, auto-hiding controls, and keyboard shortcuts.
MediaPlayerVideonative video propsplaysInline=trueVideo element with slot="media" applied. Pass <source> and <track> children as needed.
MediaPlayerAudionative audio props-Audio element with slot="media" applied.
MediaPlayerControlsnative div props-Positioned control bar that fades with player activity. Override layout with className.
MediaPlayerControlsOverlaynative div props-Decorative gradient layer for controls over video.
MediaPlayerSeeknative div props, onValueChange, step, withTimestep=5, withTime=trueTimeline control with smooth scrubbing. withTime shows the hover preview (time, thumbnail, chapter).
MediaPlayerVolumemute button props, expandable, rangeClassNameexpandable=falseMute button plus volume range.
MediaPlayerPlaybackSpeedbutton props, ratesrates=[0.5…2]Menu of playback speeds anchored to the current rate.
MediaPlayerCaptionsbutton props-Toggles captions. Disabled until the media exposes subtitle tracks.
MediaPlayerSettingsbutton props, ratesrates=[0.5…2]Settings menu with speed and caption submenus.
MediaPlayerErrornative div props-Error overlay with retry/reload actions. Renders only when the media errors; pass children to replace the default content.
control buttonsMedia Chrome button props-Play, seek backward/forward, time, PiP, fullscreen, and loop controls.

Accessibility

  • Provide captions or subtitles with <track kind="captions"> when video includes speech.
  • The player root is a focusable region; all shortcuts are also reachable through the labeled controls.
  • Use visible or implicit labels from Media Chrome controls; add aria-label overrides when surrounding context needs more specificity.
  • Keep media URLs, permissions, analytics, and product-specific state in the consuming app.

On this page