Overview
The HTML media adapter maps timeline clips to one mounted HTMLMediaElement. It seeks the element to the active clip source time, lets the native media clock drive playback, and keeps object URLs out of timeline state. The package root is imperative and framework-free; React hooks are published from ./react.
This is the right adapter for straightforward previews. If you need decoded frames on a canvas, custom Mediabunny inputs, or timeline-clocked audio playback outside a native media element, use the Mediabunny adapter instead.
Install
pnpm add @techsquidtv/canvas-timeline-html-media-adapternpm install @techsquidtv/canvas-timeline-html-media-adapteryarn add @techsquidtv/canvas-timeline-html-media-adapterbun add @techsquidtv/canvas-timeline-html-media-adapterChoose this adapter for
- Your preview is a single native
<video>or<audio>element. - Browser-native media loading, controls, and embedded audio are enough for the editor preview.
- You want URL,
Blob, orFilesources keyed byclip.sourceIdwithout managing object URLs yourself.
Usage
Connect one media element to timeline playback
Use useHTMLTimelineMedia from the ./react entry point for the normal React path. It creates the adapter, wires it to timeline playback, returns transport helpers, and exposes immutable source lifecycle snapshots.
- 1Give each media clip a stable
sourceId. - 2Create a
sourcesarray of{ sourceId, input }descriptors, one per logical source. - 3Resolve originals or proxies in your media library, then pass equivalent load
fallbacksonly when needed. - 4Create the hook with sources and a layer selector inside a
TimelineProvider. - 5Attach the returned
mediaRefto one<video>or<audio>element. - 6Treat
readyas element-connection readiness and inspectsourceStateByIdfor native source loading or recovery.
Example
import { useHTMLTimelineMedia } from '@techsquidtv/canvas-timeline-html-media-adapter/react';
const sources = [ { sourceId: 'clip-source-main', input: '/media/preview.mp4', },] as const;const layers = { visuals: { trackKind: 'visual', sourceId: 'clip-source-main' },} as const;
export function NativePreview() { const media = useHTMLTimelineMedia({ sources, layers, onError: (error) => console.error(error.reason, error.message), });
return <video ref={media.mediaRef} playsInline onClick={() => void media.play()} />;}