π₯ Make videos programmatically with React
player improvements
Jonny Burger56433a1d6093
diff --git a/packages/docs/components/LandingPage/PricingTable.tsx b/packages/docs/components/LandingPage/PricingTable.tsxindex 838663a32b..23c538e868 100644--- a/packages/docs/components/LandingPage/PricingTable.tsx+++ b/packages/docs/components/LandingPage/PricingTable.tsx@@ -49,9 +49,13 @@ export const PricingTable: React.FC<{}> = () => {</li></ul><div style={{ flex: 1 }} />- <BlueButton fullWidth disabled loading={false} size="bg">- No signup required- </BlueButton>+ <a className={styles.pricinga} href="/docs">+ <div>+ <BlueButton fullWidth loading={false} size="bg">+ Get started+ </BlueButton>+ </div>+ </a></div></div><Spacer />diff --git a/packages/docs/docs/player/autoplay.md b/packages/docs/docs/player/autoplay.mdnew file mode 100644index 0000000000..68947168d2--- /dev/null+++ b/packages/docs/docs/player/autoplay.md@@ -0,0 +1,54 @@+---+id: autoplay+sidebar_label: "Autoplay"+title: "Combatting autoplay issues"+slug: /player/autoplay+---++Browsers place restrictions on websites that play audio without user interaction. Read on how to properly use the Remotion Player so you don't run into a browser policy.++## Trigger the play from a user event++Don't autoplay audio on site load, or else browsers will block the audio. Instead, display a play button or use the [`controls`](/docs/player#controls) prop.++## Pass the event to the `play()` or `toggle()` method++The play must be initialized from a user gesture, for example a mouse click. You should get a Javascript event like a `MouseEvent` from it. Pass this event to the `play()` or `toggle()` function so audio may play automatically.++```tsx twoslash+// @allowUmdGlobalAccess+// @filename: ./remotion/MyComp.tsx+export const MyComp = () => <></>;++// @filename: index.tsx+// ---cut---+import { useRef } from "react";+import { Player, PlayerRef } from "@remotion/player";++export const App: React.FC = () => {+ const ref = useRef<PlayerRef>(null);+ return (+ <div>+ {/* Player implementation */}+ <button+ onClick={(e) => {+ const { current } = ref;+ current?.toggle(e);+ }}+ >+ Play+ </button>+ </div>+ );+};+```++## Use the `numberOfSharedAudioTags` property++If your audio does not enter the video immediately (say the few seconds of the video are silent, but then the audio fades in), it technically doesn't start based on an user interation. To combat this issue, you can use the [`numberOfSharedAudioTags`](/docs/player#numberofsharedaudiotags) property. This will play some silent audio on the first play with user interaction, and then reuse that tag to play your deferred audio playback.++You can have as many silent audio tags as you want. Set `numberOfSharedAudioTags={2}` to prepare two shared audio tags. Be mindful: If you set this props and you render more [`<Audio/>`](/docs/player/audio) than there are shared audio tags, an exception will be thrown.++:::warning+Due to a bug on our side, this prop does not work with React Strict Mode. If you use Next.JS, set `reactStrictMode: false,` in your `next.config.js` to `false`. Remove any `<React.StrictMode/>` tags in your app if you intend to use this prop. You can follow this bug on [GitHub](https://github.com/remotion-dev/remotion/issues/723).+:::diff --git a/packages/docs/docs/player-examples.md b/packages/docs/docs/player/player-examples.mdsimilarity index 99%rename from packages/docs/docs/player-examples.mdrename to packages/docs/docs/player/player-examples.mdindex 256d866151..58e49604e4 100644--- a/packages/docs/docs/player-examples.md+++ b/packages/docs/docs/player/player-examples.md@@ -1,5 +1,5 @@----id: player-examples+id: examplessidebar_label: "Examples"title: "Examples for @remotion/player"slug: /player/examplesdiff --git a/packages/docs/docs/player-integration.md b/packages/docs/docs/player/player-integration.mdsimilarity index 99%rename from packages/docs/docs/player-integration.mdrename to packages/docs/docs/player/player-integration.mdindex 8e301c225e..9cac6d180c 100644--- a/packages/docs/docs/player-integration.md+++ b/packages/docs/docs/player/player-integration.md@@ -1,5 +1,5 @@----id: player-integration+id: integrationsidebar_label: "Integrate into your app"title: "Integrating Player into your app"slug: /player/integrationdiff --git a/packages/docs/docs/player.md b/packages/docs/docs/player/player.mdsimilarity index 95%rename from packages/docs/docs/player.mdrename to packages/docs/docs/player/player.mdindex a4b0d34791..e9d9493d09 100644--- a/packages/docs/docs/player.md+++ b/packages/docs/docs/player/player.md@@ -1,12 +1,13 @@---id: playertitle: "@remotion/player"+slug: /player---import Tabs from '@theme/Tabs';import TabItem from '@theme/TabItem';-import { PlayerExample } from "../components/Player.tsx";-import { ExperimentalBadge } from "../components/Experimental.tsx";+import { PlayerExample } from "../../components/Player.tsx";+import { ExperimentalBadge } from "../../components/Experimental.tsx";<ExperimentalBadge message="This player is currently in a beta state. We are done with the most important features we wanted to implement and will promote the Player to stable in the next version, if there is no feedback from users."/>@@ -206,14 +207,24 @@ Pause the video. Nothing happens if the video is already paused.Play the video. Nothing happens if the video is already playing.+If you play the video from a user gesture, pass the `SyntheticEvent` in as an argument so [browser autoplay restrictions do not apply](/docs/player/autoplay).+### `toggle()`Pauses the video if it's playing. Plays the video if it's paused.+If you play the video from a user gesture, pass the `SyntheticEvent` in as an argument so [browser autoplay restrictions do not apply](/docs/player/autoplay).+### `getCurrentFrame()`Gets the current postition expressed as the current frame. Divide by the `fps` you passed to get the time in seconds.+### `isPlaying()`++_Available from v2.5.6_++Returns a boolean indicating whether the video is playing.+### `getContainerNode()`_Available from v2.4.2_diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 32fffc23d0..ecfdecb405 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -5,9 +5,10 @@ module.exports = {label: "β Back to main docs",href: "/docs",},- "player",- "player-examples",- "player-integration",+ "player/player",+ "player/examples",+ "player/integration",+ "player/autoplay",],someSidebar: [{diff --git a/packages/player/src/PlayerUI.tsx b/packages/player/src/PlayerUI.tsxindex a09f26b7ef..e660141ffe 100644--- a/packages/player/src/PlayerUI.tsx+++ b/packages/player/src/PlayerUI.tsx@@ -161,6 +161,7 @@ const PlayerUI: React.ForwardRefRenderFunction<toggle,getContainerNode: () => container.current,getCurrentFrame: player.getCurrentFrame,+ isPlaying: () => player.playing,seekTo: (f) => {const lastFrame = durationInFrames - 1;const frameToSeekTo = Math.max(0, Math.min(lastFrame, f));diff --git a/packages/player/src/player-methods.ts b/packages/player/src/player-methods.tsindex 9635d3e2d4..493f82408c 100644--- a/packages/player/src/player-methods.ts+++ b/packages/player/src/player-methods.ts@@ -14,6 +14,7 @@ export type PlayerMethods = {setVolume: (num: number) => void;getVolume: () => number;isMuted: () => boolean;+ isPlaying: () => boolean;mute: () => void;unmute: () => void;};