Usage
Reads the nearest MediaPlayer’s playback state and returns the actions that drive it, for custom controls inside a MediaPlayer.
tsimport {useMediaPlayer} from '@astryxdesign/lab'
Returns
| Field | Type | Description |
|---|---|---|
| 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. |
| 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 / reload | function | Fullscreen, caption track selection, and loading the source again after an error. |
Examples
Common configurations, variations, and states.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.bashnpx shadcn@4.19.0 add https://astryx-33ob69kqn-fbopensource.vercel.app/shadcn/hooks/lab/use-media-player.json