🎥 Make videos programmatically with React
player
Jonny Burger180c2010e62a
diff --git a/packages/docs/blog/2021-05-06-remotion-2-1.md b/packages/docs/blog/2021-05-06-remotion-2-1.mdindex c6071de6c1..29b29a56c8 100644--- a/packages/docs/blog/2021-05-06-remotion-2-1.md+++ b/packages/docs/blog/2021-05-06-remotion-2-1.md@@ -7,7 +7,7 @@ author_url: https://github.com/JonnyBurgerauthor_image_url: https://avatars2.githubusercontent.com/u/1629785?s=460&u=12eb94da6070d00fc924761ce06e3a428d01b7e9&v=4----import { PlayerExample } from "../components/Player.tsx";+import { PlayerExampleWithControls } from "../components/PlayerExampleWithControls.tsx";import { ExperimentalBadge } from "../components/Experimental.tsx";This releases features new utility functions, improved developer experience and an experimental release of the Remotion Player!@@ -48,7 +48,7 @@ We invested time in making sure that if something goes wrong, you don't get stucWe are working on a Remotion player component that you can import into your React app. Today we are prereleasing the player for those who wish to experiment and provide us with feedback. Let us know what you think-<PlayerExample />+<PlayerExampleWithControls />## Test coverage updatesdiff --git a/packages/docs/components/Player.tsx b/packages/docs/components/Player.tsxdeleted file mode 100644index b44191ee1e..0000000000--- a/packages/docs/components/Player.tsx+++ /dev/null@@ -1,51 +0,0 @@-import { Player } from "@remotion/player";-import React, { useState } from "react";-import { ColorDemo } from "./ColorDemo";-import "./input-fields.css";--export const PlayerExample: React.FC = () => {- const [name, setName] = useState("");-- const [color, setColor] = useState("#4098f5");- return (- <div>- <Player- component={ColorDemo}- compositionWidth={1280}- compositionHeight={720}- controls- durationInFrames={350}- fps={30}- inputProps={{- name,- color,- }}- style={{- width: "100%",- }}- loop- />- <br />- <p>- Enter your name:{" "}- <input- type="text"- placeholder="Your name"- value={name}- onChange={(e) => setName(e.target.value)}- style={{- backgroundColor: "#fffee4",- }}- />- </p>- <p>- Select your favorite color:{" "}- <input- type="color"- value={color}- onChange={(e) => setColor(e.target.value)}- />- </p>- </div>- );-};diff --git a/packages/docs/components/Player/ColorPicker.tsx b/packages/docs/components/Player/ColorPicker.tsxnew file mode 100644index 0000000000..e5040e5f29--- /dev/null+++ b/packages/docs/components/Player/ColorPicker.tsx@@ -0,0 +1,59 @@+import React from "react";++export const colorPickerColors = ["#686de0", "#be2edd", "#f0932b", "#f9ca24"];++export const ColorPicker: React.FC<{+ selected: string;+ onSelected: (color: string) => void;+}> = ({ selected, onSelected }) => {+ return (+ <div+ style={{+ display: "flex",+ marginTop: 15,+ flexDirection: "row",+ }}+ >+ {colorPickerColors.map((c) => {+ return (+ <div+ key={c}+ onClick={() => onSelected(c)}+ style={{+ backgroundColor: c,+ height: 40,+ width: 40,+ borderRadius: 20,+ marginRight: 8,+ cursor: "pointer",+ display: "flex",+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ {selected === c ? (+ <svg+ aria-hidden="true"+ focusable="false"+ data-prefix="fas"+ data-icon="check"+ className="svg-inline--fa fa-check fa-w-16"+ role="img"+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 512 512"+ style={{+ height: 20,+ }}+ >+ <path+ fill="white"+ d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"+ />+ </svg>+ ) : null}+ </div>+ );+ })}+ </div>+ );+};diff --git a/packages/docs/components/Player/features.module.css b/packages/docs/components/Player/features.module.cssindex a1a9eb619c..d338dd3205 100644--- a/packages/docs/components/Player/features.module.css+++ b/packages/docs/components/Player/features.module.css@@ -25,8 +25,16 @@align-items: center;}+.half {+ flex: 1;+}+@media (max-width: 1000px) {.row {+ width: 100%;flex-direction: column;}+ .half {+ width: 100%;+ }}diff --git a/packages/docs/components/Player/features.tsx b/packages/docs/components/Player/features.tsxindex bf9e950f2a..5733636dde 100644--- a/packages/docs/components/Player/features.tsx+++ b/packages/docs/components/Player/features.tsx@@ -1,18 +1,35 @@import useThemeContext from "@theme/hooks/useThemeContext";-import React from "react";+import React, { useState } from "react";import styles from "./features.module.css";--const half: React.CSSProperties = {- flex: 1,-};+import { PlayerExample } from "../PlayerExample";+import { CoolInput } from "../TextInput";+import { ColorPicker, colorPickerColors } from "../Player/ColorPicker";export const PlayerFeatures: React.FC = () => {const { isDarkTheme } = useThemeContext();+ const [name, setName] = useState("");+ const [color, setColor] = useState(colorPickerColors[0]);return (<div className={styles.container}><div className={styles.row}>- <div style={half}>+ <div className={styles.half}>+ <h2 className={styles.title}>Demo</h2>+ <p>Enter a name and pick a color and watch the video adapt.</p>+ <CoolInput+ placeholder="Enter your name"+ value={name}+ onChange={(e) => setName(e.target.value)}+ />+ <ColorPicker selected={color} onSelected={setColor} />+ </div>+ <div style={{ width: 20, height: 30 }} />+ <div className={styles.half}>+ <PlayerExample name={name} color={color} />+ </div>+ </div>+ <div className={styles.row}>+ <div className={styles.half}><h2 className={styles.title}><span className={styles.keyword}>Reactive</span> to data</h2>@@ -22,7 +39,7 @@ export const PlayerFeatures: React.FC = () => {</p></div><div style={{ width: 20 }} />- <div style={half}>+ <div className={styles.half}><videosrc={isDarkTheme ? "/img/reactive-dark.mp4" : "/img/reactive.mp4"}playsInline@@ -33,7 +50,7 @@ export const PlayerFeatures: React.FC = () => {</div></div><div className={styles.row}>- <div style={half}>+ <div className={styles.half}><h2 className={styles.title}>Extremely <span className={styles.keyword}>customizable</span></h2>@@ -45,7 +62,7 @@ export const PlayerFeatures: React.FC = () => {</p></div><div style={{ width: 20 }} />- <div style={half}>+ <div className={styles.half}><videosrc={isDarkTheme@@ -60,7 +77,7 @@ export const PlayerFeatures: React.FC = () => {</div></div><div className={styles.row}>- <div style={half}>+ <div className={styles.half}><h2 className={styles.title}>Turn it into real <span className={styles.keyword}> videos</span></h2>@@ -71,7 +88,7 @@ export const PlayerFeatures: React.FC = () => {</p></div><div style={{ width: 20 }} />- <div style={half}>+ <div className={styles.half}><videosrc={isDarkTheme ? "/img/pipeline-dark.mp4" : "/img/pipeline-light.mp4"diff --git a/packages/docs/components/PlayerExample.tsx b/packages/docs/components/PlayerExample.tsxnew file mode 100644index 0000000000..2f7bcb3b51--- /dev/null+++ b/packages/docs/components/PlayerExample.tsx@@ -0,0 +1,28 @@+import { Player } from "@remotion/player";+import React from "react";+import { ColorDemo } from "./ColorDemo";+import "./input-fields.css";++export const PlayerExample: React.FC<{ name: string; color: string }> = ({+ name,+ color,+}) => {+ return (+ <Player+ component={ColorDemo}+ compositionWidth={1280}+ compositionHeight={720}+ controls+ durationInFrames={350}+ fps={30}+ inputProps={{+ name,+ color,+ }}+ style={{+ width: "100%",+ }}+ loop+ />+ );+};diff --git a/packages/docs/components/PlayerExampleWithControls.tsx b/packages/docs/components/PlayerExampleWithControls.tsxnew file mode 100644index 0000000000..3156b72f3c--- /dev/null+++ b/packages/docs/components/PlayerExampleWithControls.tsx@@ -0,0 +1,34 @@+import { useState } from "react";+import React from "react";+import { PlayerExample } from "./PlayerExample";+import { inputStyle } from "./TextInput";++export const PlayerExampleWithControls: React.FC = () => {+ const [name, setName] = useState("");+ const [color, setColor] = useState("#4098f5");+ return (+ <div>+ <PlayerExample name={name} color={color} />+ <p>+ Enter your name:{" "}+ <input+ type="text"+ placeholder="Your name"+ value={name}+ onChange={(e) => setName(e.target.value)}+ style={{+ ...inputStyle,+ }}+ />+ </p>+ <p>+ Select your favorite color:{" "}+ <input+ type="color"+ value={color}+ onChange={(e) => setColor(e.target.value)}+ />+ </p>+ </div>+ );+};diff --git a/packages/docs/components/TextInput.tsx b/packages/docs/components/TextInput.tsxnew file mode 100644index 0000000000..ee95f795a2--- /dev/null+++ b/packages/docs/components/TextInput.tsx@@ -0,0 +1,52 @@+import React, { DetailedHTMLProps, useCallback, useState } from "react";++const LIGHT_BLUE = "#42e9f5";+const DARK_BLUE = "#4290f5";++const inputStyle: React.CSSProperties = {+ padding: 16,+ border: "none",+ outline: "none",+ borderRadius: 4,+ minWidth: 35,+ fontSize: 16,+};++const backgroundStyle = (focused: boolean): React.CSSProperties => {+ return {+ padding: 3,+ background: focused+ ? `linear-gradient(to right, ${LIGHT_BLUE}, ${DARK_BLUE})`+ : "rgba(0, 0, 0, 0.1)",+ display: "inline-block",+ transition: "1s background-color",+ borderRadius: 7,+ overflow: "hidden",+ };+};++type Props = Omit<+ DetailedHTMLProps<+ React.InputHTMLAttributes<HTMLInputElement>,+ HTMLInputElement+ >,+ "onFocus" | "onBlur"+>;++export const CoolInput: React.FC<Props> = (props) => {+ const [focus, setFocused] = useState(false);++ const onFocus = useCallback(() => {+ setFocused(true);+ }, [setFocused]);++ const onBlur = useCallback(() => {+ setFocused(false);+ }, [setFocused]);++ return (+ <div style={backgroundStyle(focus)}>+ <input style={inputStyle} {...props} onFocus={onFocus} onBlur={onBlur} />+ </div>+ );+};diff --git a/packages/docs/docs/player/player.md b/packages/docs/docs/player/player.mdindex 9a17bb2b48..15939be192 100644--- a/packages/docs/docs/player/player.md+++ b/packages/docs/docs/player/player.md@@ -6,7 +6,7 @@ slug: /playerimport Tabs from '@theme/Tabs';import TabItem from '@theme/TabItem';-import { PlayerExample } from "../../components/Player.tsx";+import { PlayerExampleWithControls } from "../../components/PlayerExampleWithControls.tsx";import { ExperimentalBadge } from "../../components/Experimental.tsx";Using the Remotion Player you can embed Remotion videos in any React app and customize the video content at runtime.@@ -14,7 +14,7 @@ Using the Remotion Player you can embed Remotion videos in any React app and cus## DemoPlay the video, then tweak the parameters below the video.-<PlayerExample />+<PlayerExampleWithControls />## Installation