{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "video-player",
  "type": "registry:ui",
  "title": "Video Player",
  "description": "The parts of a video player around a `<video>` element the project renders: a frame that keeps its shape, controls that step back while it plays, play, mute, volume, time, a scrubber, captions, speed, full screen, and words for loading and failure.",
  "categories": [
    "ui"
  ],
  "dependencies": [
    "lucide-react",
    "radix-ui"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/announce",
    "@rivier-ui/cn",
    "@rivier-ui/dropdown-menu",
    "@rivier-ui/scrubber",
    "@rivier-ui/spinner",
    "@rivier-ui/use-media"
  ],
  "files": [
    {
      "path": "registry/ui/video-player.tsx",
      "type": "registry:ui",
      "target": "components/ui/video-player.tsx",
      "content": "\"use client\";\n/**\n * @name video-player\n * @category ui\n * @description The parts of a video player around a `<video>` element the project renders: a frame that keeps its shape, controls that step back while it plays, play, mute, volume, time, a scrubber, captions, speed, full screen, and words for loading and failure.\n * @when Any video a person controls: a clip on a page, a lesson, a recording. The project gives the element its sources (a file, or HLS attached to the element); the parts only drive it, so compose the ones the clip needs. Nothing plays by itself: for a silent, looping decoration use a plain `<video muted loop>` with its own pause control. For sound alone use audio-player; for a picture viewer use lightbox.\n * @example\n * <VideoPlayer aria-label=\"How the kiln is loaded\" defaultCaptions>\n *   <VideoPlayerVideo src=\"/kiln.mp4\" poster=\"/kiln.jpg\">\n *     <track kind=\"captions\" src=\"/kiln.en.vtt\" srcLang=\"en\" label=\"English\" />\n *   </VideoPlayerVideo>\n *   <VideoPlayerLoading />\n *   <VideoPlayerError />\n *   <Captions />\n *   <VideoPlayerControls>\n *     <VideoPlayerScrubber />\n *     <VideoPlayerControlsRow>\n *       <VideoPlayerPlay />\n *       <VideoPlayerMute />\n *       <VideoPlayerVolume />\n *       <VideoPlayerTime />\n *       <VideoPlayerCaptionsButton className=\"ms-auto\" />\n *       <VideoPlayerRate />\n *       <VideoPlayerFullscreen />\n *     </VideoPlayerControlsRow>\n *   </VideoPlayerControls>\n * </VideoPlayer>\n */\nimport { Captions as CaptionsIcon, CaptionsOff, Maximize, Minimize, Pause, Play, RotateCcw, Volume2, VolumeX } from \"lucide-react\";\nimport { DropdownMenu as MenuPrimitive, Slider as SliderPrimitive } from \"radix-ui\";\nimport {\n  createContext,\n  use,\n  useCallback,\n  useEffect,\n  useImperativeHandle,\n  useRef,\n  useState,\n  useSyncExternalStore,\n  type ComponentProps,\n  type KeyboardEvent,\n  type MouseEvent,\n  type ReactNode,\n} from \"react\";\nimport { DropdownMenu, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger } from \"@/components/ui/dropdown-menu\";\nimport { Scrubber, ScrubberPreview, ScrubberThumb, ScrubberTrack, type ScrubberProps } from \"@/components/ui/scrubber\";\nimport { Spinner } from \"@/components/ui/spinner\";\nimport { announce } from \"@/lib/announce\";\nimport { cn } from \"@/lib/cn\";\nimport { MediaContext, formatMediaRate, formatMediaTime, isTypingTarget, nextMediaRate, useMediaContext, useMediaProvider, useOptionalMediaContext, type MediaProviderOptions } from \"@/lib/use-media\";\n\n/** Every word the player says. Pass `labels` to translate any of them. */\nexport type VideoPlayerLabels = {\n  play: string;\n  pause: string;\n  mute: string;\n  unmute: string;\n  volume: string;\n  seek: string;\n  captions: string;\n  captionsOff: string;\n  captionsOn: string;\n  noCaptions: string;\n  rate: string;\n  enterFullscreen: string;\n  exitFullscreen: string;\n  controls: string;\n  loading: string;\n  error: string;\n  retry: string;\n  muted: string;\n  unmuted: string;\n};\n\nconst LABELS: VideoPlayerLabels = {\n  play: \"Play\",\n  pause: \"Pause\",\n  mute: \"Mute\",\n  unmute: \"Unmute\",\n  volume: \"Volume\",\n  seek: \"Seek\",\n  captions: \"Captions\",\n  captionsOff: \"Off\",\n  captionsOn: \"Captions on\",\n  noCaptions: \"Captions off\",\n  rate: \"Playback speed\",\n  enterFullscreen: \"Full screen\",\n  exitFullscreen: \"Exit full screen\",\n  controls: \"Video controls\",\n  loading: \"Loading\",\n  error: \"This video could not be played.\",\n  retry: \"Try again\",\n  muted: \"Muted\",\n  unmuted: \"Sound on\",\n};\n\ntype VideoContextValue = {\n  labels: VideoPlayerLabels;\n  frame: HTMLDivElement | null;\n  fullscreen: boolean;\n  toggleFullscreen: () => void;\n  controlsShown: boolean;\n  /** A press on the picture: plays or pauses, except a touch that only brought the controls back. */\n  pressPicture: (event: MouseEvent<HTMLElement>) => void;\n};\n\nconst VideoContext = createContext<VideoContextValue | null>(null);\n\nfunction useVideo(part: string): VideoContextValue {\n  const context = use(VideoContext);\n  if (!context) throw new Error(`<${part}> must be used inside <VideoPlayer>.`);\n  return context;\n}\n\nconst subscribeFullscreen = (onChange: () => void): (() => void) => {\n  document.addEventListener(\"fullscreenchange\", onChange);\n  return () => document.removeEventListener(\"fullscreenchange\", onChange);\n};\nconst fullscreenElement = (): Element | null => document.fullscreenElement;\nconst noFullscreenElement = (): Element | null => null;\n\n/**\n * Shares one player with parts that sit outside its frame: a Transcript, a SceneStrip or a HotspotList under\n * the video. Wrap the VideoPlayer and those parts in it, and give it (not the VideoPlayer) the `locale` and\n * the captions props. It draws nothing.\n */\nexport function VideoPlayerProvider({ children, ...options }: MediaProviderOptions & { children?: ReactNode }) {\n  const media = useMediaProvider(options);\n  return <MediaContext value={media}>{children}</MediaContext>;\n}\n\nexport type VideoPlayerProps = ComponentProps<\"div\"> &\n  MediaProviderOptions & {\n    /** Width / height of the frame. Default 16 / 9. The frame keeps this shape before the video loads, so nothing jumps. */\n    aspect?: number;\n    /** Milliseconds without the pointer moving before the controls step back while playing. Default 3000. */\n    hideAfter?: number;\n    /** Seconds Left and Right move by. Default 5. */\n    seekStep?: number;\n    labels?: Partial<VideoPlayerLabels>;\n  };\n\n/**\n * The frame, and the keyboard for the whole player while focus is anywhere inside it: Space or K plays and\n * pauses, Left and Right go back and forward five seconds (time runs left to right in every language, like\n * the bar), Up and Down change the volume, M mutes, C switches captions, F is full screen, Home and End go\n * to the start and the end. The keys are left alone while typing in a field, and a slider or a menu inside\n * keeps its own arrows. Name the player with `aria-label` (what the video is). `captions`,\n * `defaultCaptions` and `onCaptionsChange` control whether captions show.\n */\nexport function VideoPlayer({\n  className,\n  style,\n  aspect = 16 / 9,\n  hideAfter = 3000,\n  seekStep = 5,\n  labels,\n  locale,\n  captions,\n  defaultCaptions,\n  onCaptionsChange,\n  children,\n  onKeyDown,\n  onPointerMove,\n  onPointerDownCapture,\n  onFocus,\n  onBlur,\n  ...props\n}: VideoPlayerProps) {\n  // Inside a VideoPlayerProvider the player joins it; alone, it is its own.\n  const outer = useOptionalMediaContext();\n  const own = useMediaProvider({ locale, captions, defaultCaptions, onCaptionsChange });\n  const media = outer ?? own;\n  const { state, actions } = media;\n  const words = { ...LABELS, ...labels };\n  const [frame, setFrame] = useState<HTMLDivElement | null>(null);\n\n  // Full screen: the browser's, or where it is refused (an iPhone), the frame fixed over the whole viewport.\n  const nativeElement = useSyncExternalStore(subscribeFullscreen, fullscreenElement, noFullscreenElement);\n  const [pseudo, setPseudo] = useState(false);\n  const fullscreen = pseudo || (frame !== null && nativeElement === frame);\n  const toggleFullscreen = (): void => {\n    if (!frame) return;\n    if (pseudo) setPseudo(false);\n    else if (document.fullscreenElement === frame) void document.exitFullscreen();\n    else if (typeof frame.requestFullscreen === \"function\") frame.requestFullscreen().catch(() => setPseudo(true));\n    else setPseudo(true);\n  };\n\n  // Controls: shown while paused, while the pointer moves, and while the keyboard is inside.\n  const [active, setActive] = useState(true);\n  const [keyboardInside, setKeyboardInside] = useState(false);\n  const timer = useRef<number | undefined>(undefined);\n  const hiddenAtPress = useRef(false);\n  const controlsShown = !state.playing || active || keyboardInside;\n  const wake = (): void => {\n    setActive(true);\n    window.clearTimeout(timer.current);\n    timer.current = window.setTimeout(() => setActive(false), hideAfter);\n  };\n  useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  const pressPicture = (event: MouseEvent<HTMLElement>): void => {\n    const touch = (event.nativeEvent as PointerEvent).pointerType === \"touch\";\n    if (touch && hiddenAtPress.current) return;\n    actions.toggle();\n  };\n\n  const toggleCaptions = (): void => {\n    announce(media.captions ? words.noCaptions : words.captionsOn);\n    media.setCaptions(!media.captions);\n  };\n\n  const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {\n    onKeyDown?.(event);\n    wake();\n    if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey || isTypingTarget(event.target)) return;\n    const target = event.target as HTMLElement;\n    const onSlider = target.closest(\"[role=slider]\") !== null;\n    const onButton = target.closest(\"button, a, [role=button], [role=menuitemradio]\") !== null;\n    const key = event.key.length === 1 ? event.key.toLowerCase() : event.key;\n    const act: Record<string, (() => void) | undefined> = {\n      \" \": onButton ? undefined : actions.toggle,\n      k: actions.toggle,\n      ArrowLeft: onSlider ? undefined : () => actions.seekBy(-seekStep),\n      ArrowRight: onSlider ? undefined : () => actions.seekBy(seekStep),\n      ArrowUp: onSlider ? undefined : () => actions.setVolume(state.volume + 0.1),\n      ArrowDown: onSlider ? undefined : () => actions.setVolume(state.volume - 0.1),\n      Home: onSlider ? undefined : () => actions.seek(0),\n      End: onSlider ? undefined : () => actions.seek(state.duration),\n      m: () => {\n        announce(state.muted ? words.unmuted : words.muted);\n        actions.toggleMuted();\n      },\n      c: toggleCaptions,\n      f: toggleFullscreen,\n      Escape: pseudo ? () => setPseudo(false) : undefined,\n    };\n    const run = act[key];\n    if (!run) return;\n    event.preventDefault();\n    run();\n  };\n\n  return (\n    <MediaContext value={media}>\n      <VideoContext value={{ labels: words, frame, fullscreen, toggleFullscreen, controlsShown, pressPicture }}>\n        <div\n          ref={setFrame}\n          data-slot=\"video-player\"\n          role=\"group\"\n          tabIndex={0}\n          data-controls={controlsShown ? \"shown\" : \"hidden\"}\n          data-playing={state.playing ? \"\" : undefined}\n          data-fullscreen={fullscreen ? \"\" : undefined}\n          className={cn(\n            \"group/player @container relative isolate w-full min-w-0 overflow-hidden rounded-surface border bg-muted text-foreground\",\n            fullscreen && \"rounded-none border-0\",\n            pseudo && \"fixed inset-0 z-50 h-dvh\",\n            className,\n          )}\n          style={{ ...(fullscreen ? {} : { aspectRatio: String(aspect) }), ...style }}\n          onKeyDown={handleKeyDown}\n          onPointerMove={(event) => {\n            onPointerMove?.(event);\n            wake();\n          }}\n          onPointerDownCapture={(event) => {\n            onPointerDownCapture?.(event);\n            hiddenAtPress.current = !controlsShown;\n            wake();\n          }}\n          onFocus={(event) => {\n            onFocus?.(event);\n            if ((event.target as HTMLElement).matches(\":focus-visible\")) setKeyboardInside(true);\n          }}\n          onBlur={(event) => {\n            onBlur?.(event);\n            if (!event.currentTarget.contains(event.relatedTarget)) setKeyboardInside(false);\n          }}\n          {...props}\n        >\n          {children}\n        </div>\n      </VideoContext>\n    </MediaContext>\n  );\n}\n\n/**\n * The `<video>` itself: give it `src` or `<source>` children, `<track>` children for captions, and a\n * `poster`. It plays inline on phones and never by itself. Pressing the picture plays or pauses; on a touch\n * screen the first tap only brings the controls back.\n */\nexport function VideoPlayerVideo({ className, ref, onClick, children, ...props }: ComponentProps<\"video\">) {\n  const { media, setMedia } = useMediaContext(\"VideoPlayerVideo\");\n  const { pressPicture } = useVideo(\"VideoPlayerVideo\");\n  // The player holds the element; a ref from the project is given the same one.\n  useImperativeHandle(ref, () => media as HTMLVideoElement, [media]);\n  return (\n    <video\n      ref={setMedia}\n      data-slot=\"video-player-video\"\n      playsInline\n      preload=\"metadata\"\n      onClick={(event) => {\n        onClick?.(event);\n        if (!event.defaultPrevented) pressPicture(event);\n      }}\n      className={cn(\"absolute inset-0 size-full bg-muted object-contain\", className)}\n      {...props}\n    >\n      {children}\n    </video>\n  );\n}\n\n/**\n * The bar of controls along the bottom, a named group. While the video plays it fades out after the pointer\n * has been still; it stays while the video is paused and while keyboard focus is inside the player, and it\n * can always be reached with Tab. It tells the frame its height, so captions sit above it.\n */\nexport function VideoPlayerControls({ className, ...props }: ComponentProps<\"div\">) {\n  const { labels } = useVideo(\"VideoPlayerControls\");\n  const measure = useCallback((node: HTMLDivElement | null) => {\n    const frame = node?.closest<HTMLElement>(\"[data-slot=video-player]\");\n    if (!node || !frame || typeof ResizeObserver === \"undefined\") return;\n    const observer = new ResizeObserver(() => frame.style.setProperty(\"--rui-controls-h\", `${node.offsetHeight}px`));\n    observer.observe(node);\n    return () => observer.disconnect();\n  }, []);\n  return (\n    <div\n      ref={measure}\n      data-slot=\"video-player-controls\"\n      role=\"group\"\n      aria-label={labels.controls}\n      className={cn(\n        \"absolute inset-x-0 bottom-0 z-20 flex flex-col border-t bg-card px-2 pt-1 pb-1 text-card-foreground transition-[opacity,translate] duration-base ease-out group-data-[controls=hidden]/player:pointer-events-none group-data-[controls=hidden]/player:translate-y-2 group-data-[controls=hidden]/player:opacity-0 motion-reduce:transition-none motion-reduce:group-data-[controls=hidden]/player:translate-y-0\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\n/** One row of controls. Push a control to the end with `className=\"ms-auto\"`. */\nexport function VideoPlayerControlsRow({ className, ...props }: ComponentProps<\"div\">) {\n  return <div data-slot=\"video-player-controls-row\" className={cn(\"flex min-w-0 items-center gap-1\", className)} {...props} />;\n}\n\ntype ControlButtonProps = Omit<ComponentProps<\"button\">, \"type\">;\n\nfunction ControlButton({ className, ...props }: ControlButtonProps) {\n  return (\n    <button\n      type=\"button\"\n      className={cn(\n        \"inline-flex h-8 min-w-8 shrink-0 items-center justify-center gap-1 rounded-control px-1.5 text-sm font-medium text-foreground transition-[background-color,opacity] duration-instant ease-out select-none hover:bg-accent disabled:pointer-events-none disabled:opacity-50 motion-reduce:transition-none pointer-coarse:h-(--control-h) pointer-coarse:min-w-(--control-h) [&_svg]:size-4 [&_svg]:shrink-0\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\n/** Plays or pauses. Its name is what pressing it will do: \"Play\", then \"Pause\". */\nexport function VideoPlayerPlay({ children, onClick, ...props }: ControlButtonProps) {\n  const { state, actions } = useMediaContext(\"VideoPlayerPlay\");\n  const { labels } = useVideo(\"VideoPlayerPlay\");\n  return (\n    <ControlButton\n      data-slot=\"video-player-play\"\n      aria-label={state.playing ? labels.pause : labels.play}\n      onClick={(event) => {\n        onClick?.(event);\n        if (!event.defaultPrevented) actions.toggle();\n      }}\n      {...props}\n    >\n      {children ?? (state.playing ? <Pause aria-hidden=\"true\" strokeWidth={1.5} /> : <Play aria-hidden=\"true\" strokeWidth={1.5} />)}\n    </ControlButton>\n  );\n}\n\n/** Mutes or unmutes: a toggle whose name stays \"Mute\" and whose pressed state says whether it is on. */\nexport function VideoPlayerMute({ children, onClick, ...props }: ControlButtonProps) {\n  const { state, actions } = useMediaContext(\"VideoPlayerMute\");\n  const { labels } = useVideo(\"VideoPlayerMute\");\n  const silent = state.muted || state.volume === 0;\n  return (\n    <ControlButton\n      data-slot=\"video-player-mute\"\n      aria-label={labels.mute}\n      aria-pressed={silent}\n      onClick={(event) => {\n        onClick?.(event);\n        if (event.defaultPrevented) return;\n        if (state.volume === 0) actions.setVolume(1);\n        else actions.toggleMuted();\n      }}\n      {...props}\n    >\n      {children ?? (silent ? <VolumeX aria-hidden=\"true\" strokeWidth={1.5} /> : <Volume2 aria-hidden=\"true\" strokeWidth={1.5} />)}\n    </ControlButton>\n  );\n}\n\nexport type VideoPlayerVolumeProps = Omit<ComponentProps<typeof SliderPrimitive.Root>, \"value\" | \"defaultValue\" | \"onValueChange\" | \"min\" | \"max\">;\n\n/** A slider for the volume. Phones set the volume with their own buttons and ignore it, so hide it at narrow widths (`hidden @md:flex`). */\nexport function VideoPlayerVolume({ className, ...props }: VideoPlayerVolumeProps) {\n  const { state, actions, locale } = useMediaContext(\"VideoPlayerVolume\");\n  const { labels } = useVideo(\"VideoPlayerVolume\");\n  const volume = state.muted ? 0 : state.volume;\n  return (\n    <SliderPrimitive.Root\n      data-slot=\"video-player-volume\"\n      min={0}\n      max={1}\n      step={0.05}\n      value={[volume]}\n      onValueChange={([next]) => {\n        if (next !== undefined) actions.setVolume(next);\n      }}\n      className={cn(\"relative flex h-8 w-20 shrink-0 touch-none items-center select-none pointer-coarse:h-(--control-h)\", className)}\n      {...props}\n    >\n      <SliderPrimitive.Track className=\"relative h-1.5 w-full grow overflow-hidden rounded-full bg-border-strong\">\n        <SliderPrimitive.Range className=\"absolute h-full bg-primary\" />\n      </SliderPrimitive.Track>\n      <SliderPrimitive.Thumb\n        aria-label={labels.volume}\n        aria-valuetext={new Intl.NumberFormat(locale, { style: \"percent\" }).format(volume)}\n        className=\"relative block size-4 shrink-0 rounded-full border border-primary bg-background after:absolute after:-inset-3\"\n      />\n    </SliderPrimitive.Root>\n  );\n}\n\n/** Elapsed and total time, in figures of equal width so the row does not shift. Not a live region: the scrubber says the time when asked. */\nexport function VideoPlayerTime({ className, ...props }: ComponentProps<\"span\">) {\n  const { state, locale } = useMediaContext(\"VideoPlayerTime\");\n  return (\n    <span data-slot=\"video-player-time\" className={cn(\"shrink-0 px-1.5 text-xs whitespace-nowrap text-muted-foreground tabular-nums\", className)} {...props}>\n      <span data-slot=\"video-player-elapsed\" className=\"text-foreground\">\n        {formatMediaTime(state.time, locale)}\n      </span>\n      {\" / \"}\n      <span data-slot=\"video-player-duration\">{formatMediaTime(state.duration, locale)}</span>\n    </span>\n  );\n}\n\nexport type VideoPlayerScrubberProps = Omit<ScrubberProps, \"value\" | \"defaultValue\" | \"duration\" | \"buffered\">;\n\n/** The scrubber, bound to the video: it follows the clock, shows what has loaded, and seeks once when let go. Children replace its parts (add a ScrubberPreview with a `thumbnail`). */\nexport function VideoPlayerScrubber({ onValueCommit, children, ...props }: VideoPlayerScrubberProps) {\n  const { state, actions, locale } = useMediaContext(\"VideoPlayerScrubber\");\n  const { labels } = useVideo(\"VideoPlayerScrubber\");\n  return (\n    <Scrubber\n      aria-label={labels.seek}\n      locale={locale}\n      value={state.time}\n      duration={state.duration}\n      buffered={state.buffered}\n      onValueCommit={(time) => {\n        actions.seek(time);\n        onValueCommit?.(time);\n      }}\n      {...props}\n    >\n      {children ?? (\n        <>\n          <ScrubberTrack />\n          <ScrubberThumb />\n          <ScrubberPreview />\n        </>\n      )}\n    </Scrubber>\n  );\n}\n\n/**\n * Switches captions on and off: a toggle with a pressed state. When the video has several caption tracks it\n * opens a menu of them instead, with \"Off\" first. It is disabled when the video has no caption track, unless\n * `available` says the project supplies cues itself (Captions with `cues`).\n */\nexport function VideoPlayerCaptionsButton({ children, onClick, available, ...props }: ControlButtonProps & { available?: boolean }) {\n  const media = useMediaContext(\"VideoPlayerCaptionsButton\");\n  const { labels, frame } = useVideo(\"VideoPlayerCaptionsButton\");\n  const { tracks } = media.state;\n  const icon = children ?? (media.captions ? <CaptionsIcon aria-hidden=\"true\" strokeWidth={1.5} /> : <CaptionsOff aria-hidden=\"true\" strokeWidth={1.5} />);\n\n  if (tracks.length < 2) {\n    return (\n      <ControlButton\n        data-slot=\"video-player-captions-button\"\n        aria-label={labels.captions}\n        aria-pressed={media.captions}\n        disabled={!(available ?? tracks.length > 0)}\n        onClick={(event) => {\n          onClick?.(event);\n          if (!event.defaultPrevented) media.setCaptions(!media.captions);\n        }}\n        {...props}\n      >\n        {icon}\n      </ControlButton>\n    );\n  }\n\n  const chosen = media.captions && media.captionTrack !== null ? String(media.captionTrack) : \"off\";\n  return (\n    // Not modal: the rest of the player stays usable, and nothing outside the frame is touched in full screen.\n    <DropdownMenu modal={false}>\n      <DropdownMenuTrigger asChild>\n        <ControlButton data-slot=\"video-player-captions-button\" aria-label={labels.captions} {...props}>\n          {icon}\n        </ControlButton>\n      </DropdownMenuTrigger>\n      {/* Inside the frame, not <body>: in full screen only the frame's own content is drawn. */}\n      <MenuPrimitive.Portal container={frame}>\n        <MenuPrimitive.Content\n          data-slot=\"video-player-captions-menu\"\n          side=\"top\"\n          align=\"end\"\n          sideOffset={6}\n          collisionPadding={8}\n          className=\"z-50 min-w-36 rounded-surface border border-border-strong bg-popover p-1 text-sm text-popover-foreground\"\n        >\n          <DropdownMenuRadioGroup\n            value={chosen}\n            onValueChange={(value) => {\n              if (value === \"off\") media.setCaptions(false);\n              else {\n                media.setCaptionTrack(Number(value));\n                media.setCaptions(true);\n              }\n            }}\n          >\n            <DropdownMenuRadioItem value=\"off\">{labels.captionsOff}</DropdownMenuRadioItem>\n            {tracks.map((track) => (\n              <DropdownMenuRadioItem key={track.index} value={String(track.index)} lang={track.language || undefined}>\n                {track.label || track.language}\n              </DropdownMenuRadioItem>\n            ))}\n          </DropdownMenuRadioGroup>\n        </MenuPrimitive.Content>\n      </MenuPrimitive.Portal>\n    </DropdownMenu>\n  );\n}\n\nconst RATES = [1, 1.25, 1.5, 2, 0.75] as const;\n\n/** The playback speed: each press goes to the next of `rates` and says it. Its name carries the speed (\"Playback speed: 1.5×\"). */\nexport function VideoPlayerRate({ rates = RATES, onClick, children, ...props }: ControlButtonProps & { rates?: readonly number[] }) {\n  const { state, actions, locale } = useMediaContext(\"VideoPlayerRate\");\n  const { labels } = useVideo(\"VideoPlayerRate\");\n  return (\n    <ControlButton\n      data-slot=\"video-player-rate\"\n      aria-label={`${labels.rate}: ${formatMediaRate(state.rate, locale)}`}\n      onClick={(event) => {\n        onClick?.(event);\n        if (event.defaultPrevented) return;\n        const next = nextMediaRate(rates, state.rate);\n        actions.setRate(next);\n        announce(`${labels.rate}: ${formatMediaRate(next, locale)}`);\n      }}\n      {...props}\n    >\n      {children ?? <span dir=\"ltr\" className=\"min-w-8 text-center text-xs tabular-nums\">{formatMediaRate(state.rate, locale)}</span>}\n    </ControlButton>\n  );\n}\n\n/** Enters and leaves full screen. Where the browser refuses (an iPhone), the frame is fixed over the whole viewport instead and Escape leaves it. */\nexport function VideoPlayerFullscreen({ children, onClick, ...props }: ControlButtonProps) {\n  const { labels, fullscreen, toggleFullscreen } = useVideo(\"VideoPlayerFullscreen\");\n  return (\n    <ControlButton\n      data-slot=\"video-player-fullscreen\"\n      aria-label={fullscreen ? labels.exitFullscreen : labels.enterFullscreen}\n      onClick={(event) => {\n        onClick?.(event);\n        if (!event.defaultPrevented) toggleFullscreen();\n      }}\n      {...props}\n    >\n      {children ?? (fullscreen ? <Minimize aria-hidden=\"true\" strokeWidth={1.5} /> : <Maximize aria-hidden=\"true\" strokeWidth={1.5} />)}\n    </ControlButton>\n  );\n}\n\n/** Shown while the video waits for data: a spinner with a name, over the picture. */\nexport function VideoPlayerLoading({ className, children, ...props }: ComponentProps<\"div\">) {\n  const { state } = useMediaContext(\"VideoPlayerLoading\");\n  const { labels } = useVideo(\"VideoPlayerLoading\");\n  if (!state.waiting) return null;\n  return (\n    <div data-slot=\"video-player-loading\" className={cn(\"pointer-events-none absolute inset-0 z-10 flex items-center justify-center\", className)} {...props}>\n      {children ?? (\n        <span className=\"inline-flex items-center gap-2 rounded-control border bg-card px-3 py-2 text-sm text-card-foreground\">\n          <Spinner size=\"sm\" label={labels.loading} />\n          <span aria-hidden=\"true\">{labels.loading}</span>\n        </span>\n      )}\n    </div>\n  );\n}\n\n/** Shown when the video cannot be played: the reason in words, announced at once, and a button that loads it again. Children replace the default message and button. */\nexport function VideoPlayerError({ className, children, ...props }: ComponentProps<\"div\">) {\n  const { state, actions } = useMediaContext(\"VideoPlayerError\");\n  const { labels } = useVideo(\"VideoPlayerError\");\n  if (state.error === null) return null;\n  return (\n    <div\n      data-slot=\"video-player-error\"\n      role=\"alert\"\n      className={cn(\"absolute inset-0 z-30 flex flex-col items-center justify-center gap-3 bg-card p-4 text-center text-sm text-card-foreground\", className)}\n      {...props}\n    >\n      {children ?? (\n        <>\n          <p>{labels.error}</p>\n          <ControlButton data-slot=\"video-player-retry\" className=\"border border-border-strong px-3\" onClick={actions.reload}>\n            <RotateCcw aria-hidden=\"true\" strokeWidth={1.5} />\n            {labels.retry}\n          </ControlButton>\n        </>\n      )}\n    </div>\n  );\n}\n\n/** A slot over the picture, above the controls: a title, a badge, a large play button. It ignores the pointer unless its children take it. */\nexport function VideoPlayerOverlay({ className, ...props }: ComponentProps<\"div\">) {\n  return <div data-slot=\"video-player-overlay\" className={cn(\"pointer-events-none absolute inset-0 z-10 flex items-center justify-center *:pointer-events-auto\", className)} {...props} />;\n}\n"
    }
  ],
  "meta": {
    "category": "ui",
    "when": "Any video a person controls: a clip on a page, a lesson, a recording. The project gives the element its sources (a file, or HLS attached to the element); the parts only drive it, so compose the ones the clip needs. Nothing plays by itself: for a silent, looping decoration use a plain `<video muted loop>` with its own pause control. For sound alone use audio-player; for a picture viewer use lightbox.",
    "example": "<VideoPlayer aria-label=\"How the kiln is loaded\" defaultCaptions>\n  <VideoPlayerVideo src=\"/kiln.mp4\" poster=\"/kiln.jpg\">\n    <track kind=\"captions\" src=\"/kiln.en.vtt\" srcLang=\"en\" label=\"English\" />\n  </VideoPlayerVideo>\n  <VideoPlayerLoading />\n  <VideoPlayerError />\n  <Captions />\n  <VideoPlayerControls>\n    <VideoPlayerScrubber />\n    <VideoPlayerControlsRow>\n      <VideoPlayerPlay />\n      <VideoPlayerMute />\n      <VideoPlayerVolume />\n      <VideoPlayerTime />\n      <VideoPlayerCaptionsButton className=\"ms-auto\" />\n      <VideoPlayerRate />\n      <VideoPlayerFullscreen />\n    </VideoPlayerControlsRow>\n  </VideoPlayerControls>\n</VideoPlayer>",
    "client": true
  }
}
