Use Media PlayerCanary · @astryxdesign/lab v0.1.9 · useMediaPlayer Lab · npm install @astryxdesign/lab@canary

Usage

Reads the nearest MediaPlayer’s playback state and returns the actions that drive it, for custom controls inside a MediaPlayer.

ts
import {useMediaPlayer} from '@astryxdesign/lab'

Returns

FieldTypeDescription
state

isPaused, isEnded, isWaiting, hasStarted, currentTime, duration (0 before metadata, Infinity when live), bufferedEnd, volume, isMuted, playbackRate, isFullscreen, canFullscreen, canSetVolume, textTracks, activeTextTrackId, and error.

play / pause / togglePaused() => void

Start and stop playback. play resolves after the browser accepts or refuses.

seek / seekBy(seconds: number) => void

Move the playhead to a time, or by an offset, clamped to the media.

setVolume / setMuted / toggleMuted(value) => void

Change the volume (0 to 1) and mute state.

setPlaybackRate(rate: number) => void

Change the speed.

toggleFullscreen / setTextTrack / toggleCaptions / reloadfunction

Fullscreen, caption track selection, and loading the source again after an error.

Examples

Common configurations, variations, and states.
Custom layout
Open in Playground

A one-row player built from the parts, with the speed as a menu and Mute with its volume slider. Every part reads the MediaPlayer around it, and useMediaPlayer turns the playback state into a custom readout.

Use with shadcn

Already using the shadcn registry workflow? Install the real Astryx package and a local public re-export. Component implementation source stays in Astryx.

This install URL expires with the draft preview.
bash
npx shadcn@4.19.0 add https://astryx-11q8a6st7-fbopensource.vercel.app/shadcn/hooks/lab/use-media-player.json