VayuUI

VideoPlayer

A compound video player with auto-hiding controls, fullscreen, subtitles, keyboard shortcuts, and WCAG 2.2 AA compliance.

Usage

Buffering...Loading video…
Big Buck Bunny (HLS)

Big Buck Bunny (HLS)

Blender Foundation

0:000:00
import { VideoPlayer } from "@/components/ui/videoplayer"

<VideoPlayer.Root>
  <VideoPlayer.Video src="/video.mp4" poster="/poster.jpg" />
  <VideoPlayer.CenterPlayButton />
  <VideoPlayer.LoadingOverlay />
  <VideoPlayer.Controls>
    <VideoPlayer.ProgressBar />
    <div className="flex items-center justify-between">
      <div className="flex items-center gap-1">
        <VideoPlayer.PlayPauseButton />
        <VideoPlayer.SkipBackwardButton />
        <VideoPlayer.SkipForwardButton />
        <VideoPlayer.VolumeControl />
        <VideoPlayer.TimeDisplay />
      </div>
      <div className="flex items-center gap-1">
        <VideoPlayer.SubtitlesButton />
        <VideoPlayer.FullscreenButton />
      </div>
    </div>
  </VideoPlayer.Controls>
</VideoPlayer.Root>

Features

  • Compound component pattern — compose sub-components freely
  • Auto-hiding controls with configurable delay
  • Fullscreen support with toggle button
  • Subtitle/caption track support
  • Progress bar with buffer indicator, hover tooltip, seek handle
  • Volume control with mute toggle and animated slider
  • forwardRef on all sub-components
  • useMemo on context value for performance
  • Keyboard shortcuts (container-scoped)
  • WCAG 2.2 AA compliant

Sub-components

ComponentDescription
RootContext provider, keyboard listener, auto-hide
VideoThe <video> element (click to toggle play)
ControlsBottom control bar with gradient overlay
ProgressBarSeekable slider with buffer + hover tooltip
PlayPauseButtonPlay / pause toggle
SkipBackwardButtonSkip backward (default 10s)
SkipForwardButtonSkip forward (default 10s)
VolumeControlMute toggle + volume slider
TimeDisplayCurrent time / duration
FullscreenButtonFullscreen toggle
SubtitlesButtonToggle subtitles/captions
SettingsButtonSettings (extensible)
DownloadButtonDownload source video
LoadingOverlayBuffering spinner overlay
CenterPlayButtonLarge center play (hidden when playing)

Root Props

PropTypeDefaultDescription
onPlay() => voidPlay callback
onPause() => voidPause callback
onEnded() => voidEnded callback
onTimeUpdate(time: number) => voidTime callback
onVolumeChange(vol: number) => voidVolume callback
onFullscreenChange(fs: boolean) => voidFullscreen callback
defaultVolumenumber1Initial volume (0–1)
defaultPlaybackRatenumber1Initial speed
autoHideControlsbooleantrueAuto-hide controls
autoHideDelaynumber3000Hide delay in ms

Keyboard Shortcuts

KeyAction
Space / KPlay / pause
← → / J / LSeek ±5s
↑ ↓Volume ±10%
MMute toggle
FFullscreen toggle
CToggle subtitles
Home / 0Seek to start
EndSeek to end

Utility Hooks

Imported from @/components/ui/hook:

HookDescription
useWatchTimeTrack total and session watch time
useVideoAnalyticsRecord events and milestone tracking
useVideoChaptersChapter navigation with auto-detection
usePlaybackSpeedStepped speed control
useVideoBufferBuffer health monitoring
useVideoQualityStream quality switching
useVideoStateSyncResume position via localStorage
useVideoHotkeysCustom keyboard shortcuts

On this page