Skip to content

🎥 Make videos programmatically with React

moved preview ui to @remotion/player

Shankhadeep Deyc264407bb7bd
diff --git a/packages/player-example/src/App.tsx b/packages/player-example/src/App.tsx
index a89e59edd5..a31dd465c7 100644
--- a/packages/player-example/src/App.tsx
+++ b/packages/player-example/src/App.tsx
@@ -1,45 +1,5 @@
-import React, { useState, useRef, useEffect } from "react";
-import VideoPreview from "./VideoPreview";
-import { Internals } from "remotion";
-
-const slides = [
- {
- imageUrl: "./images/silverado-back-left.jpg",
- caption: "What an amazing car!",
- transition: "transition_fade"
- },
- {
- imageUrl: "./images/silverado-back-right.jpg",
- caption: "Buy it now, the price is right",
- transition: "transition_fade"
- },
- {
- imageUrl: "./images/silverado-front.jpg",
- caption: "Looks good from the front",
- transition: "transition_fade"
- },
- {
- imageUrl: "./images/silverado-left.jpg",
- caption: "She's a beauty",
- transition: "transition_fade"
- }
-];
+import {RemotionPlayer} from '@remotion/player';
export default function App() {
- const rootRef = useRef<React.FC | null>(null);
- const Root = rootRef.current;
- const [isInitialized, setIsInitialized] = useState(false);
- useEffect(() => {
- const Root = Internals.getRoot();
- rootRef.current = Root;
- setIsInitialized(true);
- }, []);
- return Root && isInitialized ? (
- <Internals.RemotionRoot>
- <Root />
- <div className="App">
- <VideoPreview slides={slides} />
- </div>
- </Internals.RemotionRoot>
- ) : null;
+ return <RemotionPlayer id={'main'} />;
}
diff --git a/packages/player-example/src/RemotionVideo.tsx b/packages/player-example/src/RemotionVideo.tsx
index 1a100f8ec2..658570f9aa 100644
--- a/packages/player-example/src/RemotionVideo.tsx
+++ b/packages/player-example/src/RemotionVideo.tsx
@@ -1,20 +1,20 @@
-import React, { FunctionComponent } from "react";
-import { Composition } from "remotion";
-import CarSlideshow from "./CarSlideshow";
+import React, {FunctionComponent} from 'react';
+import {Composition} from 'remotion';
+import CarSlideshow from './CarSlideshow';
const RemotionVideo: FunctionComponent = () => {
- return (
- <>
- <Composition
- id="car-slideshow"
- component={CarSlideshow}
- width={768}
- height={432}
- fps={30}
- durationInFrames={500}
- />
- </>
- );
+ return (
+ <>
+ <Composition
+ id="main"
+ component={CarSlideshow}
+ width={768}
+ height={432}
+ fps={30}
+ durationInFrames={500}
+ />
+ </>
+ );
};
-export default RemotionVideo;
\ No newline at end of file
+export default RemotionVideo;
diff --git a/packages/player/src/RemotionPlayer.tsx b/packages/player/src/RemotionPlayer.tsx
new file mode 100644
index 0000000000..f9a4dfa180
--- /dev/null
+++ b/packages/player/src/RemotionPlayer.tsx
@@ -0,0 +1,30 @@
+import React, {useEffect, useRef, useState} from 'react';
+import {Internals} from 'remotion';
+import RemotionRootComponent from './RemotionRootComponent';
+
+type Props = {
+ id: string;
+};
+
+const Loading: React.FC = () => <h1>Loading…</h1>;
+
+export const RemotionPlayer: React.FC<Props> = ({id}) => {
+ const rootRef = useRef<React.FC | null>(null);
+ const Root = rootRef.current;
+ const [isInitialized, setIsInitialized] = useState(false);
+
+ useEffect(() => {
+ const Root = Internals.getRoot();
+ rootRef.current = Root;
+ setIsInitialized(true);
+ }, []);
+
+ return Root && isInitialized ? (
+ <Internals.RemotionRoot>
+ <Root />
+ <div className="App">
+ <RemotionRootComponent id={id} />
+ </div>
+ </Internals.RemotionRoot>
+ ) : null;
+};
diff --git a/packages/player-example/src/VideoPreview.tsx b/packages/player/src/RemotionRootComponent.tsx
similarity index 81%
rename from packages/player-example/src/VideoPreview.tsx
rename to packages/player/src/RemotionRootComponent.tsx
index ddd719e2b3..cc5a080183 100644
--- a/packages/player-example/src/VideoPreview.tsx
+++ b/packages/player/src/RemotionRootComponent.tsx
@@ -1,30 +1,22 @@
-import {usePlaybackTime} from '@remotion/player';
import React, {Suspense, useContext, useEffect} from 'react';
import {Internals} from 'remotion';
-
-export type Props = {
- slides: {
- imageUrl: string;
- caption: string;
- transition: string;
- }[];
-};
+import {usePlaybackTime} from './PlayPause';
const Loading: React.FC = () => <h1>Loading…</h1>;
-const VideoPreview: React.FC<Props> = ({slides}) => {
+const RemotionRootComponent: React.FC<{id: string}> = ({id}) => {
const {setCurrentComposition, currentComposition} = useContext(
Internals.CompositionManager
);
const config = Internals.useUnsafeVideoConfig();
+ const [toggle] = usePlaybackTime();
+ const [playing] = Internals.Timeline.usePlayingState();
const video = Internals.useVideo();
const VideoComponent = video ? video.component : null;
- const [playing] = Internals.Timeline.usePlayingState();
- const [toggle] = usePlaybackTime();
useEffect(() => {
if (!currentComposition) {
- setCurrentComposition('car-slideshow');
+ setCurrentComposition(id);
}
if (!config) {
@@ -32,6 +24,8 @@ const VideoPreview: React.FC<Props> = ({slides}) => {
}
}, [config, currentComposition, setCurrentComposition]);
+ console.log(currentComposition, 'video');
+
return (
<Suspense fallback={Loading}>
<h1>Remotion Video Player</h1>
@@ -62,4 +56,4 @@ const VideoPreview: React.FC<Props> = ({slides}) => {
);
};
-export default VideoPreview;
+export default RemotionRootComponent;
diff --git a/packages/player/src/index.ts b/packages/player/src/index.ts
deleted file mode 100644
index 10cb24ff97..0000000000
--- a/packages/player/src/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from './PlayPause';
diff --git a/packages/player/src/index.tsx b/packages/player/src/index.tsx
new file mode 100644
index 0000000000..fb2a0e29b3
--- /dev/null
+++ b/packages/player/src/index.tsx
@@ -0,0 +1,2 @@
+export * from './PlayPause';
+export {RemotionPlayer} from './RemotionPlayer';