Overview
The Mediabunny adapter is for timeline preview monitors that need decoded media, not just a mounted <video> tag. It opens registered sources only when active or explicitly preloaded, paints decoded video frames to a canvas, queues audio through Web Audio, and exposes per-source timing and track metadata.
In React, start with useMediabunnyTimelineMedia from ./react. It creates the adapter and connects it to timeline playback. The package root stays framework-free for imperative integrations. Drop down to useMediabunnyAdapter or createMediabunnyAdapter only when you are building custom sync, sharing an adapter between controls, or owning lifecycle outside React.
Install
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 mediabunnyUsage
Decode media without putting media in timeline state
Timeline clips keep lightweight sourceId values. Your app keeps the actual files, URLs, or Mediabunny inputs outside the timeline and passes matching source descriptors to the adapter.
- 1Give each media clip a stable
sourceId. - 2Create a
sourcesarray where each logical source has a matchingsourceIdand app-resolvedinput. - 3Resolve originals or proxies in app state and use
fallbacksonly for equivalent transport failover. - 4Pass sources and visual/audio layer selectors to
useMediabunnyTimelineMediainside aTimelineProvider. - 5Attach the returned
canvasRefto the canvas that receives decoded video frames. - 6Use
sourceStateByIdfor lazy loading and source metadata; preload likely next clips and unload resources no longer needed. - 7Use the returned transport helpers for playback and
useMediabunnyFrameTimeonly for UI that needs live decoded-frame timestamps.
Example
import { useMediabunnyTimelineMedia } from '@techsquidtv/canvas-timeline-mediabunny-adapter/react';
const sourceId = 'clip-source-main';const sources = [{ sourceId, input: '/media/preview.mp4',}] as const;const layers = { visuals: { trackKind: 'visual', sourceId }, audio: { trackKind: 'audio', sourceId },} as const;
export function DecodedPreview() { const media = useMediabunnyTimelineMedia({ sources, layers, onError: (error) => console.error(error.reason, error.message), });
return <canvas ref={media.canvasRef} width={1280} height={720} onClick={() => void media.play()} />;}