-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86ec6b9
commit 63ef0d7
Showing
4 changed files
with
88 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,38 @@ | ||
import React from "react"; | ||
// In the AudioOutput component | ||
import React, { useEffect, useRef } from "react"; | ||
|
||
function AudioOutput() { | ||
return <></>; | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters