Skip to content

🎥 Make videos programmatically with React

new preload

Jonny Burger9bd819956765
diff --git a/packages/player-example/src/MyAudio.tsx b/packages/player-example/src/MyAudio.tsx
new file mode 100644
index 0000000000..aa718f72b7
--- /dev/null
+++ b/packages/player-example/src/MyAudio.tsx
@@ -0,0 +1,38 @@
+import {Audio} from 'remotion';
+import React, {useEffect, useRef, useState} from 'react';
+
+const src =
+ 'https://staging_b.backend.studio.vime.ai/v1/api/videos/preview?text=%3Cmstts:express-as%20style=%27neutral%27%3ELorem%20Ipsum%20is%20simply%20dummy%20text%20of%20the%20printing%20and%20typesetting%20industry.%20Lorem%20Ipsum%20has%20been%3C/mstts:express-as%3E&voiceId=sara';
+
+export const getData = async (src: string) => {
+ const response = await fetch(src);
+ if (!response.ok) {
+ throw new Error(`HTTP error, status = ${response.status}`);
+ }
+ const buffer = await response.blob();
+ return URL.createObjectURL(buffer);
+};
+
+export const MyAudio: React.FC = () => {
+ const [state, setState] = useState<string | null>(null);
+ const ref = useRef<HTMLAudioElement>(null);
+
+ useEffect(() => {
+ getData(src)
+ .then((arrBuffer) => {
+ setState(arrBuffer);
+ if (ref.current && state) {
+ ref.current.src = state;
+ }
+ })
+ .catch((err) => {
+ console.log(err);
+ });
+ }, [state]);
+
+ if (state) {
+ return <audio ref={ref} controls />;
+ }
+
+ return null;
+};
diff --git a/packages/player-example/src/index.tsx b/packages/player-example/src/index.tsx
index 5b7c818c2d..27a0dd6dd4 100644
--- a/packages/player-example/src/index.tsx
+++ b/packages/player-example/src/index.tsx
@@ -2,6 +2,7 @@ import React, {ComponentType} from 'react';
import {createRoot} from 'react-dom/client';
import App from './App';
import CarSlideshow from './CarSlideshow';
+import {MyAudio} from './MyAudio';
import {VideoautoplayDemo} from './VideoAutoplay';
const rootElement = document.getElementById('root');
@@ -27,6 +28,7 @@ createRoot(rootElement as HTMLElement).render(
}}
>
<React.StrictMode>
+ <MyAudio />
<App lazyComponent={Car} durationInFrames={500} />
<App component={VideoautoplayDemo} durationInFrames={2700} />
</React.StrictMode>