-
Notifications
You must be signed in to change notification settings - Fork 1
/
AudioOutput.jsx
38 lines (33 loc) · 970 Bytes
/
AudioOutput.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// In the AudioOutput component
import React, { useEffect, useRef } from "react";
function AudioOutput({ currentAudioBuffer }) {
const audioRef = useRef(null);
useEffect(() => {
if (currentAudioBuffer) {
console.log(
"Creating blob with ArrayBuffer of size:",
currentAudioBuffer.byteLength
);
const blob = new Blob([currentAudioBuffer], { type: "audio/mp3" });
const url = URL.createObjectURL(blob);
console.log("Blob URL:", url); // Check the generated URL
audioRef.current.src = url;
audioRef.current
.play()
.catch((err) => console.error("Error playing audio:", err));
return () => {
console.log("Revoking URL:", url);
URL.revokeObjectURL(url);
};
}
}, [currentAudioBuffer]);
return (
<audio
ref={audioRef}
controls
autoPlay
onLoadedData={() => console.log("Audio loaded")}
/>
);
}
export default AudioOutput;