# Media widget

A talk, recording or podcast in the chat with chapters an assistant wrote, cut into the scrubber and listed below.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Media widget. A recorded talk with chapters the assistant wrote. Jump to a chapter, or press N for the next one. Preview: https://chatcn.dev/preview/media-widget-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/media-widget
```

## Usage

```tsx
import { MediaWidget } from "@/components/ui/chatcn/pro/media-widget"

<MediaWidget
  title="How we cut checkout latency"
  meta={["Engineering all hands", "18:42"]}
  src="/talks/checkout.mp4"
  poster="/talks/checkout.webp"
  chapters={[
    { at: 0, title: "Why checkout felt slow" },
    { at: 472, title: "The fix: reuse the session customer" },
  ]}
/>
```

The scrubber is cut into the chapters with small gaps, so the shape of the recording is visible before you play it; hovering it shows the time and the chapter there. The current chapter is named over the controls and lit in the list below, with a thin bar filling as it plays; a chapter row jumps and plays. Speed, picture in picture (with a real video) and full screen sit in the control bar, which fades while video plays and returns on hover or focus. The keyboard works like a video site: Space or K to play, J and L to skip ten seconds, arrows for five, N and P for chapters. `kind="audio"` drops the picture for a compact bar. Without `src` it plays a clock over the poster, for demos.

## Examples

### States

Example: States. Audio with chapters, and a short video with none. Preview: https://chatcn.dev/preview/media-widget-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `title`, `meta` |  | The heading and its quiet line |
| `kind` | `"video" | "audio"` | Default video |
| `src`, `poster` | `string` | The file and its still |
| `duration` | `number` | Seconds; read from the file when there is one |
| `chapters` | `MediaChapter[]` | `{ at, title }`, in seconds |
| `rates` | `number[]` | Speeds offered. Default 1, 1.25, 1.5 and 2 |
| `labels` | `Partial<MediaWidgetLabels>` | Every string, for translation |

## Keyboard

| Key | Action |
| --- | --- |
| Space, K | Play or pause |
| J, L | Back or forward ten seconds |
| Arrow left, right | Back or forward five seconds |
| N, P | Next or previous chapter |

## Accessibility

- The scrubber is a slider that reads the time, the length and the chapter.
- Chapter rows are buttons named with the title and the time; the current one is marked.

## Motion

The controls fade in 200 ms while video plays. Chapter progress moves with transform.

Source: https://chatcn.dev/docs/components/media-widget