🎥 Make videos programmatically with React
also test for more cases
Jonny Burger5e977f0a885c
diff --git a/packages/docs/docs/player/player-examples.md b/packages/docs/docs/player/player-examples.mdindex 7f4ba80f33..750bb9eb16 100644--- a/packages/docs/docs/player/player-examples.md+++ b/packages/docs/docs/player/player-examples.md@@ -8,18 +8,18 @@ title: "Examples for @remotion/player"```tsx twoslash// @allowUmdGlobalAccess-// @filename: ./remotion/MyComp.tsx-export const MyComp = () => <></>;+// @filename: ./remotion/MyVideo.tsx+export const MyVideo = () => <></>;// @filename: index.tsx// ---cut---import { Player } from "@remotion/player";-import { MyComp } from "./remotion/MyComp";+import { MyVideo } from "./remotion/MyVideo";export const App: React.FC = () => {return (<Player- component={MyComp}+ component={MyVideo}durationInFrames={120}compositionWidth={1920}compositionHeight={1080}@@ -33,18 +33,18 @@ export const App: React.FC = () => {```tsx twoslash {12}// @allowUmdGlobalAccess-// @filename: ./remotion/MyComp.tsx-export const MyComp = () => <></>;+// @filename: ./remotion/MyVideo.tsx+export const MyVideo = () => <></>;// @filename: index.tsx// ---cut---import { Player } from "@remotion/player";-import { MyComp } from "./remotion/MyComp";+import { MyVideo } from "./remotion/MyVideo";export const App: React.FC = () => {return (<Player- component={MyComp}+ component={MyVideo}durationInFrames={120}compositionWidth={1920}compositionHeight={1080}@@ -59,18 +59,18 @@ export const App: React.FC = () => {```tsx twoslash {13}// @allowUmdGlobalAccess-// @filename: ./remotion/MyComp.tsx-export const MyComp = () => <></>;+// @filename: ./remotion/MyVideo.tsx+export const MyVideo = () => <></>;// @filename: index.tsx// ---cut---import { Player } from "@remotion/player";-import { MyComp } from "./remotion/MyComp";+import { MyVideo } from "./remotion/MyVideo";export const App: React.FC = () => {return (<Player- component={MyComp}+ component={MyVideo}durationInFrames={120}compositionWidth={1920}compositionHeight={1080}@@ -86,18 +86,18 @@ export const App: React.FC = () => {```tsx twoslash {14-17}// @allowUmdGlobalAccess-// @filename: ./remotion/MyComp.tsx-export const MyComp = () => <></>;+// @filename: ./remotion/MyVideo.tsx+export const MyVideo = () => <></>;// @filename: index.tsx// ---cut---import { Player } from "@remotion/player";-import { MyComp } from "./remotion/MyComp";+import { MyVideo } from "./remotion/MyVideo";export const App: React.FC = () => {return (<Player- component={MyComp}+ component={MyVideo}durationInFrames={120}compositionWidth={1920}compositionHeight={1080}@@ -121,18 +121,18 @@ See [Scaling](/docs/player/scaling) for more ways to scale the Player.```tsx twoslash {18}// @allowUmdGlobalAccess-// @filename: ./remotion/MyComp.tsx-export const MyComp = () => <></>;+// @filename: ./remotion/MyVideo.tsx+export const MyVideo = () => <></>;// @filename: index.tsx// ---cut---import { Player } from "@remotion/player";-import { MyComp } from "./remotion/MyComp";+import { MyVideo } from "./remotion/MyVideo";export const App: React.FC = () => {return (<Player- component={MyComp}+ component={MyVideo}durationInFrames={120}compositionWidth={1920}compositionHeight={1080}@@ -157,13 +157,13 @@ You need to be vary of the browser's autoplay policy. In most browsers, you cann```tsx twoslash {1, 6-15, 18}// @allowUmdGlobalAccess-// @filename: ./remotion/MyComp.tsx-export const MyComp = () => <></>;+// @filename: ./remotion/MyVideo.tsx+export const MyVideo = () => <></>;// @filename: index.tsx// ---cut---import { Player, PlayerRef } from "@remotion/player";-import { MyComp } from "./remotion/MyComp";+import { MyVideo } from "./remotion/MyVideo";import { useCallback, useRef } from "react";export const App: React.FC = () => {@@ -180,7 +180,7 @@ export const App: React.FC = () => {return (<Playerref={playerRef}- component={MyComp}+ component={MyVideo}durationInFrames={120}compositionWidth={1920}compositionHeight={1080}@@ -194,13 +194,13 @@ export const App: React.FC = () => {```tsx twoslash {1, 6-21, 25}// @allowUmdGlobalAccess-// @filename: ./remotion/MyComp.tsx-export const MyComp = () => <></>;+// @filename: ./remotion/MyVideo.tsx+export const MyVideo = () => <></>;// @filename: index.tsx// ---cut---import { Player, PlayerRef } from "@remotion/player";-import { MyComp } from "./remotion/MyComp";+import { MyVideo } from "./remotion/MyVideo";import { useEffect, useRef } from "react";export const App: React.FC = () => {@@ -224,7 +224,7 @@ export const App: React.FC = () => {return (<Playerref={playerRef}- component={MyComp}+ component={MyVideo}durationInFrames={120}compositionWidth={1920}compositionHeight={1080}@@ -238,14 +238,14 @@ export const App: React.FC = () => {```tsx twoslash {6-7, 16-18}// @allowUmdGlobalAccess-// @filename: ./remotion/MyComp.tsx-export const MyComp = () => <></>;+// @filename: ./remotion/MyVideo.tsx+export const MyVideo = () => <></>;// @filename: index.tsx// ---cut---import { useState } from "react";import { Player } from "@remotion/player";-import { MyComp } from "./remotion/MyComp";+import { MyVideo } from "./remotion/MyVideo";export const App: React.FC = () => {// Connect the state to a text field@@ -253,7 +253,7 @@ export const App: React.FC = () => {return (<Player- component={MyComp}+ component={MyVideo}durationInFrames={120}compositionWidth={1920}compositionHeight={1080}diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsxindex 2007cc79af..17d16cf239 100644--- a/packages/player/src/Player.tsx+++ b/packages/player/src/Player.tsx@@ -103,10 +103,17 @@ export const PlayerFn = <T,>();}+ // @ts-expect-error+ if (componentProps.component.type === Composition) {+ throw new TypeError(+ `'component' should not be an instance of <Composition/>. Pass the React component directly, and set the duration, fps and dimensions as separate props. See https://www.remotion.dev/docs/player/examples for an example.`+ );+ }+// @ts-expect-errorif (componentProps.component === Composition) {throw new TypeError(- `'component' must not be an instance of the '<Composition \\>' component.`+ `'component' must not be the 'Composition' component. Pass your own React component directly, and set the duration, fps and dimensions as separate props. See https://www.remotion.dev/docs/player/examples for an example.`);}diff --git a/packages/player/src/test/validate-prop.test.tsx b/packages/player/src/test/validate-prop.test.tsxindex ecef88afad..84b6690999 100644--- a/packages/player/src/test/validate-prop.test.tsx+++ b/packages/player/src/test/validate-prop.test.tsx@@ -211,7 +211,42 @@ test('passing in <Composition /> instance should not be possible', () => {/>);}).toThrow(- /'component' must not be an instance of the '<Composition \\>' component./+ /'component' must not be the 'Composition' component\. Pass your own React/+ );+});+test('passing in <Composition /> instance should not be possible', () => {+ expect(() => {+ render(+ <Player+ compositionWidth={500}+ compositionHeight={400}+ fps={30}+ durationInFrames={500}+ // @ts-expect-error+ component={+ <Composition+ durationInFrames={30}+ fps={30}+ height={10}+ width={10}+ id="hello"+ component={HelloWorld}+ />+ }+ controls+ showVolumeControls+ inputProps={{+ id: 'HelloWorld',+ width: 500,+ height: 400,+ fps: 30,+ durationInFrames: 500,+ component: HelloWorld,+ }}+ />+ );+ }).toThrow(+ /'component' should not be an instance of <Composition\/>\. Pass the React component dir/);});