Installation
pnpm add @techsquidtv/canvas-timeline-mediabunny-adapter mediabunnynpm install @techsquidtv/canvas-timeline-mediabunny-adapter mediabunnyyarn add @techsquidtv/canvas-timeline-mediabunny-adapter mediabunnybun add @techsquidtv/canvas-timeline-mediabunny-adapter mediabunnyWhen to use it
How it fits together
Canvas Timeline still owns the timeline state, active clips, source offsets, and playback intent. The Mediabunny adapter owns decoded media inputs, frame sinks, optional audio scheduling, and the media clock needed to render the active visual/audio clips in sync.
Setup flow
- 1Give timeline media clips stable `sourceId` values and keep media files, blobs, or Mediabunny inputs in application state.
- 2Build a `sources` array where each item has an `id` matching a clip `sourceId` plus `url`, `blob`, `input`, or `createInput`.
- 3Attach a `canvasRef` when decoded video frames should be painted to a preview canvas.
- 4Pass `canvasRef`, `sources`, and your visual/audio layer selectors to `useMediabunnyTimelineMedia` inside a `TimelineProvider`.
- 5Pass a custom `mediabunny` module or loader only when you need explicit dependency control; otherwise the hook uses a browser lazy import.
import { useRef } from 'react';import { useMediabunnyTimelineMedia } from '@techsquidtv/canvas-timeline-mediabunny-adapter/react';
const sources = [{ id: 'clip-source-main', url: '/media/preview.mp4' }];const previewLayers = { visuals: { trackKind: 'visual', sourceId: 'clip-source-main' }, audio: { trackKind: 'audio', sourceId: 'clip-source-main' },} as const;
// Render inside <TimelineProvider engine={engine}>.export function DecodedPreview() { const canvasRef = useRef<HTMLCanvasElement>(null); const media = useMediabunnyTimelineMedia({ canvasRef, sources, layers: previewLayers, });
return <canvas ref={canvasRef} width={1280} height={720} onClick={() => void media.play()} />;}What to look for in the demo
- •The Mediabunny Adapter Sync demo uses `useMediabunnyTimelineMedia` so the visible code matches the recommended setup path.
- •`sampleSourceId` appears in the visual/audio clips and in the Mediabunny source descriptors, showing the same `clip.sourceId` join key.
- •The `canvasRef` preview receives decoded frames while the high-level hook returns the transport controls, status, duration, and last-frame readouts.
- •The status panel reads `durationBySourceId` and `lastFrameTime`, which are useful for preview UI but do not need to be copied into timeline state.
Common imports
import { useMediabunnyTimelineMedia } from '@techsquidtv/canvas-timeline-mediabunny-adapter/react';import { useMediabunnyAdapter } from '@techsquidtv/canvas-timeline-mediabunny-adapter/react';import { createMediabunnyAdapter,} from '@techsquidtv/canvas-timeline-mediabunny-adapter';Usage notes
- •`mediabunny` is a peer dependency; the high-level hook lazy-loads it in the browser by default, while low-level APIs can still receive an explicit module or loader for dependency control.
- •The adapter maps `clip.sourceId` to Mediabunny sources and keeps heavy media objects outside serialized timeline state.
- •Use `useMediabunnyTimelineMedia` for the common React path; use `useMediabunnyAdapter`, `createMediabunnyAdapter`, and `useTimelineMediaSync` when you need custom clock or layer synchronization.
- •For ordinary single-element playback, prefer the native HTML media adapter from `@techsquidtv/canvas-timeline-html-media-adapter`.
API Surface
Explore the key components, hooks, and classes exported by this package. Click any symbol to view its full TSDoc parameter signatures.
Key Entry Points
Create a Mediabunny adapter and bind it to timeline-synchronized playback.
Create a Mediabunny adapter that drives Canvas Timeline media playback.
Create and dispose a Mediabunny timeline adapter from React state.
Adapter that connects Canvas Timeline playback and frame rendering to Mediabunny.
Subpath Imports
Import specific files or modules directly to reduce bundle size or target specialized package layers.
| Import Path | Description |
|---|---|
| @techsquidtv/canvas-timeline-mediabunny-adapter | Imperative Mediabunny timeline adapter and types. |
| @techsquidtv/canvas-timeline-mediabunny-adapter/react | React hook for creating and disposing the adapter. |