Skip to content

🎥 Make videos programmatically with React

option for number of audio tags

Jonny Burger3514db093763
diff --git a/packages/bundler/src/bundle.ts b/packages/bundler/src/bundle.ts
index 6aea640667..dcf2464439 100644
--- a/packages/bundler/src/bundle.ts
+++ b/packages/bundler/src/bundle.ts
@@ -191,6 +191,7 @@ export async function bundle(...args: Arguments): Promise<string> {
inputProps: null,
remotionRoot: resolvedRemotionRoot,
previewServerCommand: null,
+ numberOfAudioTags: 0,
});
fs.writeFileSync(path.join(outDir, 'index.html'), html);
diff --git a/packages/bundler/src/index-html.ts b/packages/bundler/src/index-html.ts
index 438bf00d8c..2d6ee75cc3 100644
--- a/packages/bundler/src/index-html.ts
+++ b/packages/bundler/src/index-html.ts
@@ -8,6 +8,7 @@ export const indexHtml = ({
staticHash,
remotionRoot,
previewServerCommand,
+ numberOfAudioTags,
}: {
staticHash: string;
baseDir: string;
@@ -16,6 +17,7 @@ export const indexHtml = ({
envVariables?: Record<string, string>;
remotionRoot: string;
previewServerCommand: string | null;
+ numberOfAudioTags: number;
}) =>
`
<!DOCTYPE html>
@@ -28,6 +30,7 @@ export const indexHtml = ({
<title>Remotion Preview</title>
</head>
<body>
+ <script>window.remotion_numberOfAudioTags = ${numberOfAudioTags};</script>
<script>window.remotion_staticBase = "${staticHash}";</script>
<div id="video-container"></div>
<div id="explainer-container"></div>
diff --git a/packages/bundler/src/renderEntry.tsx b/packages/bundler/src/renderEntry.tsx
index 3749d76e34..5988de922b 100644
--- a/packages/bundler/src/renderEntry.tsx
+++ b/packages/bundler/src/renderEntry.tsx
@@ -155,7 +155,7 @@ const renderContent = () => {
if (bundleMode.type === 'composition' || bundleMode.type === 'evaluation') {
const markup = (
- <Internals.RemotionRoot>
+ <Internals.RemotionRoot numberOfAudioTags={0}>
<WaitForRoot />
<GetVideo state={bundleMode} />
</Internals.RemotionRoot>
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index f7238f873d..64e8cfcdf6 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -79,6 +79,7 @@ import {setLogLevel} from './log';
import {setMaxTimelineTracks} from './max-timeline-tracks';
import {getMuted, setMuted} from './muted';
import {getNumberOfGifLoops, setNumberOfGifLoops} from './number-of-gif-loops';
+import {setNumberOfSharedAudioTags} from './number-of-shared-audio-tags';
import {setOutputLocation} from './output-location';
import type {WebpackOverrideFn} from './override-webpack';
import {overrideWebpackConfig} from './override-webpack';
@@ -97,6 +98,7 @@ export const Config: ConfigType = {
Preview: {
setMaxTimelineTracks,
setKeyboardShortcutsEnabled,
+ setNumberOfSharedAudioTags,
},
Bundling: {
overrideWebpackConfig,
diff --git a/packages/cli/src/config/number-of-shared-audio-tags.ts b/packages/cli/src/config/number-of-shared-audio-tags.ts
new file mode 100644
index 0000000000..e5ed7a269c
--- /dev/null
+++ b/packages/cli/src/config/number-of-shared-audio-tags.ts
@@ -0,0 +1,9 @@
+let numberOfSharedAudioTags = 0;
+
+export const getNumberOfSharedAudioTags = () => {
+ return numberOfSharedAudioTags;
+};
+
+export const setNumberOfSharedAudioTags = (audioTags: number) => {
+ numberOfSharedAudioTags = audioTags;
+};
diff --git a/packages/cli/src/preview-server/routes.ts b/packages/cli/src/preview-server/routes.ts
index 10d04c571c..e27a664ab9 100644
--- a/packages/cli/src/preview-server/routes.ts
+++ b/packages/cli/src/preview-server/routes.ts
@@ -3,6 +3,7 @@ import {createReadStream, statSync} from 'fs';
import type {IncomingMessage, ServerResponse} from 'http';
import path from 'path';
import {URLSearchParams} from 'url';
+import {getNumberOfSharedAudioTags} from '../config/number-of-shared-audio-tags';
import {getFileSource} from './error-overlay/react-overlay/utils/get-file-source';
import {
getDisplayNameForEditor,
@@ -65,6 +66,7 @@ const handleFallback = async ({
remotionRoot,
previewServerCommand:
packageManager === 'unknown' ? null : packageManager.startCommand,
+ numberOfAudioTags: getNumberOfSharedAudioTags(),
})
);
};
diff --git a/packages/cli/src/previewEntry.tsx b/packages/cli/src/previewEntry.tsx
index e9f1b9cf39..894b68b97d 100644
--- a/packages/cli/src/previewEntry.tsx
+++ b/packages/cli/src/previewEntry.tsx
@@ -17,7 +17,7 @@ const getServerDisconnectedDomElement = () => {
};
const content = (
- <Internals.RemotionRoot>
+ <Internals.RemotionRoot numberOfAudioTags={window.remotion_numberOfAudioTags}>
<EditorContexts>
<Editor />
</EditorContexts>
diff --git a/packages/core/src/RemotionRoot.tsx b/packages/core/src/RemotionRoot.tsx
index 64330abfdd..b97201fa71 100644
--- a/packages/core/src/RemotionRoot.tsx
+++ b/packages/core/src/RemotionRoot.tsx
@@ -22,7 +22,8 @@ import {DurationsContextProvider} from './video/duration-state';
export const RemotionRoot: React.FC<{
children: React.ReactNode;
-}> = ({children}) => {
+ numberOfAudioTags: number;
+}> = ({children, numberOfAudioTags}) => {
const [remotionRootId] = useState(() => String(random(null)));
const [frame, setFrame] = useState<number>(window.remotion_initialFrame ?? 0);
const [playing, setPlaying] = useState<boolean>(false);
@@ -89,7 +90,7 @@ export const RemotionRoot: React.FC<{
<DurationsContextProvider>
<SharedAudioContextProvider
// In the preview, which is mostly played on Desktop, we opt out of the autoplay policy fix as described in https://github.com/remotion-dev/remotion/pull/554, as it mostly applies to mobile.
- numberOfAudioTags={0}
+ numberOfAudioTags={numberOfAudioTags}
>
{children}
</SharedAudioContextProvider>
diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts
index e69fd2196a..82df2248ff 100644
--- a/packages/core/src/config.ts
+++ b/packages/core/src/config.ts
@@ -41,6 +41,12 @@ export type ConfigType = {
* @default true
*/
readonly setKeyboardShortcutsEnabled: (enableShortcuts: boolean) => void;
+ /**
+ * Set number of shared audio tags. https://www.remotion.dev/docs/player/autoplay#use-the-numberofsharedaudiotags-property
+ * @param numberOfAudioTags
+ * @default 0
+ */
+ readonly setNumberOfSharedAudioTags: (numberOfAudioTags: number) => void;
};
readonly Bundling: {
/**
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 8438450c9e..d87d423043 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -9,6 +9,7 @@ declare global {
setBundleMode: (bundleMode: BundleState) => void;
remotion_staticBase: string;
remotion_editorName: string | null;
+ remotion_numberOfAudioTags: number;
remotion_projectName: string;
remotion_cwd: string;
remotion_previewServerCommand: string;
diff --git a/packages/core/src/test/audio.test.tsx b/packages/core/src/test/audio.test.tsx
index ef4406d511..f6eca41d36 100644
--- a/packages/core/src/test/audio.test.tsx
+++ b/packages/core/src/test/audio.test.tsx
@@ -15,7 +15,7 @@ const Wrapper: React.FC<{
const compositions = useContext(Internals.CompositionManager);
return (
<CanUseRemotionHooksProvider>
- <Internals.RemotionRoot>
+ <Internals.RemotionRoot numberOfAudioTags={0}>
<Internals.CompositionManager.Provider
// eslint-disable-next-line react/jsx-no-constructed-context-values
value={{
diff --git a/packages/core/src/test/composition-rules.test.tsx b/packages/core/src/test/composition-rules.test.tsx
index c8f38e0b66..585565048c 100644
--- a/packages/core/src/test/composition-rules.test.tsx
+++ b/packages/core/src/test/composition-rules.test.tsx
@@ -49,7 +49,7 @@ describe('Render composition-rules should throw with invalid props', () => {
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={100}
diff --git a/packages/core/src/test/composition-validation.test.tsx b/packages/core/src/test/composition-validation.test.tsx
index 90a8c6c2f6..e9c3030017 100644
--- a/packages/core/src/test/composition-validation.test.tsx
+++ b/packages/core/src/test/composition-validation.test.tsx
@@ -15,7 +15,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
{/**
// @ts-expect-error */}
<Composition
@@ -35,7 +35,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={100}
@@ -53,7 +53,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={100}
@@ -71,7 +71,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={100}
@@ -90,7 +90,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={100}
@@ -110,7 +110,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={100}
@@ -128,7 +128,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={100}
@@ -146,7 +146,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={100}
@@ -167,7 +167,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={-100}
@@ -185,7 +185,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={0}
@@ -203,7 +203,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={0.11}
@@ -221,7 +221,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
// @ts-expect-error
@@ -242,7 +242,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={100}
@@ -260,7 +260,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={100}
@@ -279,7 +279,7 @@ describe('Composition-validation render should throw with invalid props', () =>
expectToThrow(
() =>
render(
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<Composition
lazyComponent={() => Promise.resolve({default: AnyComp})}
durationInFrames={100}
diff --git a/packages/core/src/test/loop-validation.test.tsx b/packages/core/src/test/loop-validation.test.tsx
index 095b0e9ae8..186a889b0b 100644
--- a/packages/core/src/test/loop-validation.test.tsx
+++ b/packages/core/src/test/loop-validation.test.tsx
@@ -17,7 +17,7 @@ const Wrapper: React.FC<{
const compositions = useContext(CompositionManager);
return (
<CanUseRemotionHooksProvider>
- <RemotionRoot>
+ <RemotionRoot numberOfAudioTags={0}>
<CompositionManager.Provider
// eslint-disable-next-line react/jsx-no-constructed-context-values
value={{
diff --git a/packages/core/src/test/video.test.tsx b/packages/core/src/test/video.test.tsx
index 492638612a..a2eb20dc18 100644
--- a/packages/core/src/test/video.test.tsx
+++ b/packages/core/src/test/video.test.tsx
@@ -16,7 +16,7 @@ const Wrapper: React.FC<{
const compositions = useContext(Internals.CompositionManager);
return (
<CanUseRemotionHooksProvider>
- <Internals.RemotionRoot>
+ <Internals.RemotionRoot numberOfAudioTags={0}>
<Internals.CompositionManager.Provider
// eslint-disable-next-line react/jsx-no-constructed-context-values
value={{
diff --git a/packages/example/remotion.config.ts b/packages/example/remotion.config.ts
index 4b94295e33..87196ccd32 100644
--- a/packages/example/remotion.config.ts
+++ b/packages/example/remotion.config.ts
@@ -3,3 +3,5 @@ import {webpackOverride} from './src/webpack-override';
Config.Output.setOverwriteOutput(true);
Config.Bundling.overrideWebpackConfig(webpackOverride);
+
+Config.Preview.setNumberOfSharedAudioTags(3);
diff --git a/packages/renderer/src/test/get-assets-for-markup.tsx b/packages/renderer/src/test/get-assets-for-markup.tsx
index bbc8519bee..3706973935 100644
--- a/packages/renderer/src/test/get-assets-for-markup.tsx
+++ b/packages/renderer/src/test/get-assets-for-markup.tsx
@@ -97,7 +97,7 @@ export const getAssetsForMarkup = async (
return (
<Internals.CanUseRemotionHooksProvider>
- <Internals.RemotionRoot>
+ <Internals.RemotionRoot numberOfAudioTags={0}>
<Internals.CompositionManager.Provider value={value}>
<Markup />
</Internals.CompositionManager.Provider>