Skip to content

🎥 Make videos programmatically with React

@remotion/player-example: Add Canvas layers page

JonnyBurgerd25079720938
diff --git a/bun.lock b/bun.lock
index c57a6274a9..e8bc03ee74 100644
--- a/bun.lock
+++ b/bun.lock
@@ -1433,6 +1433,7 @@
"version": "4.0.516",
"dependencies": {
"@remotion/bundler": "workspace:*",
+ "@remotion/canvas": "workspace:*",
"@remotion/eslint-config-flat": "workspace:*",
"@remotion/gif": "workspace:*",
"@remotion/google-fonts": "workspace:*",
diff --git a/packages/player-example/package.json b/packages/player-example/package.json
index 88c753f8eb..b3eeb5d19e 100644
--- a/packages/player-example/package.json
+++ b/packages/player-example/package.json
@@ -12,6 +12,7 @@
],
"dependencies": {
"@remotion/bundler": "workspace:*",
+ "@remotion/canvas": "workspace:*",
"@remotion/eslint-config-flat": "workspace:*",
"@remotion/gif": "workspace:*",
"@remotion/google-fonts": "workspace:*",
@@ -29,8 +30,8 @@
"@types/node": "catalog:"
},
"scripts": {
- "formatting": "prettier src --check",
- "lint": "eslint src",
+ "formatting": "prettier src pages --check",
+ "lint": "eslint src pages",
"dev": "next dev",
"build-site": "next build",
"testnextjs": "next build"
diff --git a/packages/player-example/pages/canvas.tsx b/packages/player-example/pages/canvas.tsx
new file mode 100644
index 0000000000..e3bc16e921
--- /dev/null
+++ b/packages/player-example/pages/canvas.tsx
@@ -0,0 +1,115 @@
+import {Canvas, useCanvasController} from '@remotion/canvas';
+import React, {useSyncExternalStore} from 'react';
+import {AbsoluteFill, Sequence, useCurrentFrame} from 'remotion';
+
+const CanvasComposition: React.FC = () => {
+ const frame = useCurrentFrame();
+
+ return (
+ <AbsoluteFill
+ style={{
+ alignItems: 'center',
+ backgroundColor: '#111827',
+ color: 'white',
+ fontFamily: 'sans-serif',
+ justifyContent: 'center',
+ }}
+ >
+ <Sequence name="Background" layout="none">
+ <AbsoluteFill
+ style={{
+ background:
+ 'linear-gradient(135deg, #111827 0%, #312e81 50%, #7c3aed 100%)',
+ }}
+ />
+ </Sequence>
+ {frame < 90 ? (
+ <Sequence name="Intro card" durationInFrames={90}>
+ <h1 style={{fontSize: 88}}>Canvas</h1>
+ </Sequence>
+ ) : null}
+ {frame >= 60 ? (
+ <Sequence name="Details" from={60} durationInFrames={120}>
+ <div style={{fontSize: 54}}>Live timeline layers</div>
+ </Sequence>
+ ) : null}
+ </AbsoluteFill>
+ );
+};
+
+const CanvasPage: React.FC = () => {
+ const controller = useCanvasController();
+ const layers = useSyncExternalStore(
+ controller.timeline.subscribe,
+ controller.timeline.getSnapshot,
+ controller.timeline.getSnapshot,
+ );
+
+ return (
+ <main
+ style={{
+ fontFamily: 'sans-serif',
+ margin: '40px auto',
+ maxWidth: 1100,
+ padding: '0 20px',
+ }}
+ >
+ <h1>Canvas layers</h1>
+ <p>
+ This page renders <code>@remotion/canvas</code> and subscribes to the
+ layers currently mounted in its Player.
+ </p>
+ <div
+ style={{
+ alignItems: 'start',
+ display: 'grid',
+ gap: 32,
+ gridTemplateColumns: 'minmax(0, 2fr) minmax(240px, 1fr)',
+ }}
+ >
+ <Canvas
+ controller={controller}
+ component={CanvasComposition}
+ compositionWidth={1280}
+ compositionHeight={720}
+ durationInFrames={180}
+ fps={30}
+ controls
+ acknowledgeRemotionLicense
+ style={{width: '100%'}}
+ />
+ <section
+ style={{
+ border: '1px solid #d1d5db',
+ borderRadius: 8,
+ padding: 20,
+ }}
+ >
+ <h2 style={{marginTop: 0}}>Mounted layers ({layers.length})</h2>
+ {layers.length === 0 ? (
+ <p>No layers mounted.</p>
+ ) : (
+ <ol style={{paddingLeft: 24}}>
+ {layers.map((layer) => (
+ <li
+ key={layer.sequence.id}
+ style={{marginBottom: 12, paddingLeft: layer.depth * 16}}
+ >
+ <strong>
+ {layer.sequence.displayName ?? layer.sequence.type}
+ </strong>
+ <div style={{color: '#555', fontSize: 14}}>
+ {layer.sequence.type} · frame {layer.sequence.from} ·{' '}
+ {layer.sequence.duration} frames
+ </div>
+ </li>
+ ))}
+ </ol>
+ )}
+ </section>
+ </div>
+ </main>
+ );
+};
+
+export default CanvasPage;
diff --git a/packages/player-example/pages/index.tsx b/packages/player-example/pages/index.tsx
index 0c7e3d5497..cc258a5066 100644
--- a/packages/player-example/pages/index.tsx
+++ b/packages/player-example/pages/index.tsx
@@ -1,54 +1,75 @@
-import {Thumbnail} from '@remotion/player';
-import React from 'react';
-import App from '../src/App';
-import CarSlideshow from '../src/CarSlideshow';
-import {CustomControlsExample} from '../src/CustomControlsExample';
-import {FontPicker} from '../src/FontPicker';
-import {ThumbnailDemo} from '../src/ThumbnailDemo';
+import Link from 'next/link';
+
+const examples = [
+ {
+ href: '/player',
+ name: 'Player and thumbnail',
+ description:
+ 'The original Player testbed with custom controls and thumbnails.',
+ },
+ {
+ href: '/canvas',
+ name: 'Canvas layers',
+ description: 'A Player with a live list of mounted timeline layers.',
+ },
+ {
+ href: '/audio',
+ name: 'Audio',
+ description: 'Switch between compositions containing audio.',
+ },
+ {
+ href: '/audio-switching',
+ name: 'Audio switching',
+ description: 'Switch compositions and prefetched audio sources.',
+ },
+ {
+ href: '/autoplay-muted-video',
+ name: 'Autoplay muted video',
+ description: 'Autoplay a muted video in the Player.',
+ },
+ {
+ href: '/autoplay-unmuted-video',
+ name: 'Autoplay unmuted video',
+ description: 'Exercise browser autoplay blocking and fallback behavior.',
+ },
+ {
+ href: '/fullscreen',
+ name: 'Fullscreen',
+ description: 'A Player that fills the browser viewport.',
+ },
+ {
+ href: '/video-ssr',
+ name: 'Video SSR',
+ description: 'Render a video Player through Next.js server-side rendering.',
+ },
+ {
+ href: '/issue-7183',
+ name: 'Issue #7183',
+ description: 'Player measurement inside a 3D-transformed parent.',
+ },
+] as const;
function Index() {
return (
- <React.StrictMode>
- <FontPicker />
- <h2>Player</h2>
- <div
- style={{
- display: 'flex',
- flexDirection: 'row',
- justifyContent: 'center',
- }}
- >
- <App component={CarSlideshow} durationInFrames={500} />
- </div>
- <h2>Custom Controls</h2>
- <div
- style={{
- display: 'flex',
- flexDirection: 'row',
- justifyContent: 'center',
- }}
- >
- <CustomControlsExample />
- </div>
- <h2>Thumbnail</h2>
- <Thumbnail
- component={CarSlideshow}
- frameToDisplay={480}
- compositionHeight={200}
- compositionWidth={500}
- durationInFrames={5000}
- fps={30}
- style={{
- border: '4px solid red',
- }}
- inputProps={{
- title: 'Hi there',
- bgColor: 'black',
- color: 'white',
- }}
- />
- <ThumbnailDemo />
- </React.StrictMode>
+ <main
+ style={{
+ fontFamily: 'sans-serif',
+ margin: '40px auto',
+ maxWidth: 760,
+ padding: '0 20px',
+ }}
+ >
+ <h1>Player examples</h1>
+ <p>Choose a focused example:</p>
+ <ul style={{lineHeight: 1.5, paddingLeft: 24}}>
+ {examples.map((example) => (
+ <li key={example.href} style={{marginBottom: 16}}>
+ <Link href={example.href}>{example.name}</Link>
+ <div style={{color: '#555'}}>{example.description}</div>
+ </li>
+ ))}
+ </ul>
+ </main>
);
}
diff --git a/packages/player-example/pages/player.tsx b/packages/player-example/pages/player.tsx
new file mode 100644
index 0000000000..d60c31878b
--- /dev/null
+++ b/packages/player-example/pages/player.tsx
@@ -0,0 +1,53 @@
+import {Thumbnail} from '@remotion/player';
+import React from 'react';
+import App from '../src/App';
+import CarSlideshow from '../src/CarSlideshow';
+import {CustomControlsExample} from '../src/CustomControlsExample';
+import {FontPicker} from '../src/FontPicker';
+import {ThumbnailDemo} from '../src/ThumbnailDemo';
+
+function PlayerExample() {
+ return (
+ <React.StrictMode>
+ <FontPicker />
+ <h2>Player</h2>
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'row',
+ justifyContent: 'center',
+ }}
+ >
+ <App component={CarSlideshow} durationInFrames={500} />
+ </div>
+ <h2>Custom Controls</h2>
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'row',
+ justifyContent: 'center',
+ }}
+ >
+ <CustomControlsExample />
+ </div>
+ <h2>Thumbnail</h2>
+ <Thumbnail
+ component={CarSlideshow}
+ frameToDisplay={480}
+ compositionHeight={200}
+ compositionWidth={500}
+ durationInFrames={5000}
+ fps={30}
+ style={{border: '4px solid red'}}
+ inputProps={{
+ title: 'Hi there',
+ bgColor: 'black',
+ color: 'white',
+ }}
+ />
+ <ThumbnailDemo />
+ </React.StrictMode>
+ );
+}
+
+export default PlayerExample;
diff --git a/packages/player-example/tsconfig.json b/packages/player-example/tsconfig.json
index 82b0178265..c64bf17908 100644
--- a/packages/player-example/tsconfig.json
+++ b/packages/player-example/tsconfig.json
@@ -1,5 +1,10 @@
{
- "include": ["./src/**/*"],
+ "include": [
+ "./src/**/*",
+ "./pages/index.tsx",
+ "./pages/player.tsx",
+ "./pages/canvas.tsx"
+ ],
"compilerOptions": {
"strict": true,
"esModuleInterop": true,
@@ -19,6 +24,9 @@
"incremental": true
},
"references": [
+ {
+ "path": "../canvas"
+ },
{
"path": "../player"
},