Skip to content

Commit 3b63973

Browse files
authored
Fix type errors in Vite example app (#555)
* fix type errors in Vite example app * replace semicolons
1 parent d9710f7 commit 3b63973

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

apps/react-vite-app/src/App.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import { toBlobURL, fetchFile } from "@ffmpeg/util";
55
function App() {
66
const [loaded, setLoaded] = useState(false);
77
const ffmpegRef = useRef(new FFmpeg());
8-
const videoRef = useRef(null);
9-
const messageRef = useRef(null);
8+
const videoRef = useRef<HTMLVideoElement | null>(null)
9+
const messageRef = useRef<HTMLParagraphElement | null>(null)
1010

1111
const load = async () => {
1212
const baseURL = "https://unpkg.com/@ffmpeg/[email protected]/dist/esm";
1313
const ffmpeg = ffmpegRef.current;
1414
ffmpeg.on("log", ({ message }) => {
15-
messageRef.current.innerHTML = message;
15+
if (messageRef.current) messageRef.current.innerHTML = message;
1616
});
1717
// toBlobURL is used to bypass CORS issue, urls with the same
1818
// domain can be used directly.
@@ -35,10 +35,13 @@ function App() {
3535
const ffmpeg = ffmpegRef.current;
3636
await ffmpeg.writeFile("input.avi", await fetchFile(videoURL));
3737
await ffmpeg.exec(["-i", "input.avi", "output.mp4"]);
38-
const data = await ffmpeg.readFile("output.mp4");
39-
videoRef.current.src = URL.createObjectURL(
40-
new Blob([data.buffer], { type: "video/mp4" })
41-
);
38+
const fileData = await ffmpeg.readFile('output.mp4');
39+
const data = new Uint8Array(fileData as ArrayBuffer);
40+
if (videoRef.current) {
41+
videoRef.current.src = URL.createObjectURL(
42+
new Blob([data.buffer], { type: 'video/mp4' })
43+
)
44+
}
4245
};
4346

4447
return loaded ? (

0 commit comments

Comments
 (0)