Component

Player

The top-level composed YouTube player component.

Installation

bash
npx shadcn@latest add https://ytcn.dev/r/ytcn

Usage

components/my-player.tsx
"use client"

import { YtcnPlayer } from "@/components/ytcn/ytcn-player"

export function MyPlayer() {
  return (
    <YtcnPlayer
      videoId="dQw4w9WgXcQ"
      startAt={0}
      onEnd={() => console.log("Video ended")}
      onTimeUpdate={(current, duration) => {
        console.log(`${Math.floor(current)}s / ${Math.floor(duration)}s`)
      }}
    />
  )
}

Props

PropTypeDefaultDescription
videoId*string11-character YouTube video ID extracted from any YouTube URL. Example: "dQw4w9WgXcQ"
startAtnumber0Resume playback from this position in seconds. Useful for LMS progress tracking.
onEnd() => voidFired when video reaches the end. Use for auto-advance in playlists or course completion.
onTimeUpdate(current: number, duration: number) => voidPolled every 250ms during playback. Throttle writes to avoid excessive database calls.
keyboardShortcutsbooleantrueEnables built-in keyboard shortcuts. Disable if your app has conflicting key bindings.
classNamestringApplied to the outermost container div.

Keyboard Shortcuts

KeyAction
SpacePlay / Pause
FToggle fullscreen
MToggle mute
Seek back 10 seconds
Seek forward 10 seconds

Input safety

Shortcuts are automatically disabled when focus is on an input, textarea, or contenteditable element.

Source

View source on GitHub →