# Video player

> A hairline video player whose 3px scrubber springs open into a live filmstrip of extracted frames, with chapter micro-gaps, a return-to-spot bookmark and a Bayer buffering veil.

Default browser video controls look out of place on product changelogs, docs and course pages, and thin progress bars make finding a specific moment guesswork. VideoPlayer keeps the chrome whisper-quiet: at rest, the timeline is a 3px hairline segmented by crisp chapter gaps, and the HUD fades down to a 2px bottom whisper while playing. Hover or press the scrubber and the hairline springs open vertically into a live 38px filmstrip of the video’s real frames (extracted in the browser from a hidden copy and cached per URL, with a CORS-safe thumbnails fallback), paired with a magnified preview loupe showing the frame, chapter title and timestamp. Jumping more than 2.5 seconds away leaves a tiny amber bookmark notch where you came from plus a one-tap return pill so exploring never loses your place. Full J/K/L and arrow shortcuts, captions, playback speed, Picture-in-Picture and an 8×8 Bayer optical buffering veil are built in.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/video-player.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): none
- Docs and live preview: https://hairlineui.com/ui/video-player
- Registry item (source): https://hairlineui.com/r/video-player.json

## Usage

```tsx
import { VideoPlayer } from "@/components/video-player";

<VideoPlayer
  src="/videos/release-walkthrough.mp4"
  chapters={[
    { time: 0, title: "Overview" },
    { time: 18, title: "Keyboard shortcuts" },
    { time: 44, title: "Billing webhooks" },
  ]}
  captionSrc="/videos/release-walkthrough.vtt"
/>
```

## Product changelog video with chapter links and external seek telemetry

Pass chapters and optional WebVTT captions directly into VideoPlayer; use thumbnails if your video lives on a third-party CDN without CORS headers.

```tsx
"use client";
import { VideoPlayer, type VideoChapter } from "@/components/video-player";

const CHAPTERS: VideoChapter[] = [
  { time: 0, title: "Intro" },
  { time: 12, title: "Live search" },
  { time: 34, title: "Exporting data" },
];

export function ChangelogClip({ src, poster, thumbnails }: { src: string; poster?: string; thumbnails?: string[] }) {
  return (
    <VideoPlayer
      src={src}
      poster={poster}
      chapters={CHAPTERS}
      thumbnails={thumbnails}
      label="Release walkthrough"
      onPlayChange={(playing) => {
        if (playing) console.info("playback started");
      }}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `src / poster / aspectRatio` | `string / string / string` | `– / – / "16 / 10"` | Native MP4 or WebM video URL, optional poster image and frame aspect ratio. |
| `chapters` | `VideoChapter[]` | `[]` | Ordered { time, title } markers rendered as micro-gaps along the rail and shown in the scrub loupe and control bar. |
| `captions / captionSrc / defaultCaptions` | `VideoCaption[] / string / boolean` | `– / – / false` | Inline timed captions or a WebVTT (.vtt) URL, plus initial toggle state. |
| `thumbnails / filmstripFrames` | `string[] / number` | `– / 10` | Optional pre-generated thumbnail URLs for non-CORS streams, or number of frames to extract client-side. |
| `muted / autoPlay / loop / sound` | `boolean / boolean / boolean / boolean` | `false / false / false / false` | Standard playback flags plus opt-in Web Audio ticks on seek, bookmark return and speed change. |
| `onPlayChange / onTimeChange / label` | `(playing) => void / (t, d) => void / string` | – | Playback and progress callbacks plus accessible region title. |

## States

- **resting hairline**: When paused or hovered, controls float over a subtle bottom scrim with a crisp 3px hairline timeline segmented by chapter micro-gaps.
- **filmstrip open**: Hovering or scrubbing the rail springs the hairline open into a 38px optical strip of real video frames while a clamped magnified loupe tracks the cursor with chapter title and timestamp.
- **playing (auto-hidden)**: After 2.4s of idle playback, the HUD fades softly out leaving only a 2px bottom progress whisper; any pointer motion or key wakes it immediately.
- **bookmark active**: After any jump of 2.5s or more, a crisp amber notch marks your previous spot on the rail and an inline return pill snaps straight back in one tap.
- **buffering**: A fine 8×8 Bayer optical scan veil glides over the stage until frames arrive, sleeping completely at 0% CPU during smooth playback.
- **reduced motion**: Filmstrip open/close jumps cleanly without spring travel, center skip cues stay quiet and the buffering canvas sleeps.

## What it handles

Finding a moment inside a product recording should feel immediate without bloating your bundle with a third-party player runtime.

- **Hairline-to-filmstrip scrubber**: A 3px hairline rail segmented by chapter gaps springs open on hover or scrub into a live 38px optical strip of real extracted video frames, with a magnified preview loupe above the pointer.
- **Client-side frame cache with CORS fallback**: Extracts frames sequentially from a detached hidden video element and caches them per URL; non-CORS CDNs fall back cleanly to a thumbnails prop or a Bayer rail with zero console noise.
- **Return-to-previous-spot bookmark**: Seeking more than 2.5 seconds drops an amber notch at your old timestamp and surfaces a one-tap return pill (or press B) so you never lose your place.
- **Optical Bayer buffering veil**: While metadata loads or the stream buffers, a quiet 8×8 Bayer scan veil breathes over the stage and sleeps completely at 0% CPU once playback resumes.
- **Captions that clear the filmstrip**: Supports both inline captions arrays and WebVTT URLs; active subtitles smoothly lift clear whenever the filmstrip and loupe open.
- **Complete keyboard and touch ergonomics**: Space/K play, J/L skip 10s, arrows seek 5s or adjust volume, 0 to 9 jump percentages, C toggles captions, M mutes, F fullscreens, B returns to bookmark and double-tap skips on touch.

## Replaces

native <video controls>, video.js, plyr, custom filmstrip scrubber, framer-motion

## Where it fits

- **Product changelogs and tours**: Embed crisp MP4 walkthroughs where visitors can scrub real frames and jump straight between feature chapters.
- **Documentation and lessons**: Pair chapters, WebVTT or inline captions and J/K/L keyboard controls without pulling in a heavy media SDK.
- **Recorded calls and async reviews**: Jump around to check a slide, then tap the amber return-to-spot pill to snap straight back to where you were watching.
- **AI video generation outputs**: Frame generated clips in a hairline dark viewport with an optical Bayer buffering veil instead of a generic spinner.

## Notes

- Client-side frame extraction runs on a detached hidden video element so seeking frames never interrupts playback, and extracted frames are cached in memory per URL.
- If a video is served cross-origin without Access-Control-Allow-Origin headers, pixel reads fail gracefully with zero console noise and fall back to the thumbnails prop or an architectural Bayer rail.
- Playhead progress writes directly to the DOM inside requestAnimationFrame while playing, keeping React state free of 60fps updates.
- All filmstrip thumbnails and loupe previews render directly onto retina canvas elements with zero img element churn.
- Under prefers-reduced-motion: reduce, the filmstrip switches immediately without spring animation and the buffering canvas stays asleep.

License: MIT (https://hairlineui.com/license#components)
