shadimage
limeplay
examplecaptions-state-control-demosource: ok · hit

Captions State Control Demo

npx shadcn add "https://limeplay.winoffrg.dev/r/captions-state-control-demo.json"
free

Where it goes

stats

Interaction

animated-counter

Tags auto-generated by rules on 9/24/2026 — empty means no evidence, not lack of support.

Dependencies

Bundle weight · light

Registry dependencies

https://limeplay.winoffrg.dev/r/media-provider.jsonhttps://limeplay.winoffrg.dev/r/captions.jsonhttps://limeplay.winoffrg.dev/r/use-playback.json

Files1 · source cached 10/8/2026, 10:25:19 PM

registry/default/examples/captions-state-control-demo.tsx
"use client"

import { ClosedCaptioningIcon } from "@phosphor-icons/react"
import { useEffect } from "react"

import { Button } from "@/components/ui/button"
import { useCaptionsStore } from "@/registry/default/hooks/use-captions"
import {
  MediaReadyState,
  usePlaybackStore,
} from "@/registry/default/hooks/use-playback"
import { usePlayerStore } from "@/registry/default/hooks/use-player"
import {
  CaptionsContainer,
  CaptionsControl,
} from "@/registry/default/ui/captions"

export function CaptionsHybridDemo() {
  return <CaptionsContainer className="mb-16" />
}

export function CaptionsStateControlDemo() {
  const textTrackVisible = useCaptionsStore((state) => state.visible)
  const player = usePlayerStore((state) => state.instance)
  const readyState = usePlaybackStore((state) => state.readyState)

  // DEV: Adding text tracks externally as demo asset doesn't have built-in text tracks
  useEffect(() => {
    if (!player || readyState < MediaReadyState.HAVE_METADATA) return

    player
      .addTextTrackAsync(
        "/assets/sprite_fight.vtt",
        "en",
        "captions",
        "text/vtt",
        undefined,
        "English"
      )
      .then(() => {
        player.selectTextTrack(player.getTextTracks()[0])
      })
      .catch((error: unknown) => {
        console.error("Error adding text track:", error)
      })
  }, [readyState, player])

  return (
    <CaptionsControl asChild>
      <Button size="icon" variant="ghost">
        <ClosedCaptioningIcon
          size={18}
          weight={textTrackVisible ? "fill" : "regular"}
        />
      </Button>
    </CaptionsControl>
  )
}

More from limeplay

Browse all components in this library →