Skip to content

🎥 Make videos programmatically with React

add example for looping audio

Jonny Burgerb785641e1720
diff --git a/packages/example/src/LoopAudio/index.tsx b/packages/example/src/LoopAudio/index.tsx
new file mode 100644
index 0000000000..29ed4a82d8
--- /dev/null
+++ b/packages/example/src/LoopAudio/index.tsx
@@ -0,0 +1,39 @@
+import {getAudioDurationInSeconds} from '@remotion/media-utils';
+import React, {useEffect, useState} from 'react';
+import {
+ Audio,
+ continueRender,
+ delayRender,
+ Loop,
+ staticFile,
+ useVideoConfig,
+} from 'remotion';
+
+const LoopedAudio: React.FC = () => {
+ const [duration, setDuration] = useState<null | number>(null);
+ const [handle] = useState(() => delayRender());
+ const {fps} = useVideoConfig();
+
+ useEffect(() => {
+ getAudioDurationInSeconds(staticFile('22khz.wav'))
+ .then((d) => {
+ setDuration(d);
+ continueRender(handle);
+ })
+ .catch((err) => {
+ console.log(err);
+ });
+ }, [handle]);
+
+ if (duration === null) {
+ return null;
+ }
+
+ return (
+ <Loop durationInFrames={Math.floor(fps * duration)}>
+ <Audio src={staticFile('22khz.wav')} />
+ </Loop>
+ );
+};
+
+export default LoopedAudio;
diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsx
index ec95637e18..7030412b81 100644
--- a/packages/example/src/Video.tsx
+++ b/packages/example/src/Video.tsx
@@ -422,6 +422,14 @@ export const Index: React.FC = () => {
fps={30}
durationInFrames={180 * 30}
/>
+ <Composition
+ id="loop-audio"
+ lazyComponent={() => import('./LoopAudio')}
+ width={1080}
+ height={1080}
+ fps={30}
+ durationInFrames={180 * 30}
+ />
</Folder>
<Folder name="three">
<Still id="Orb" component={OrbScene} width={2000} height={2000} />