audio load

Signed-off-by: ale <ale@manalejandro.com>
This commit is contained in:
ale 2025-05-20 01:45:27 +02:00
parent 5f1a81abb1
commit 685d928215
Signed by: ale
GPG Key ID: 244A9C4DAB1C0C81

View File

@ -1,10 +1,9 @@
import "./App.css"; import "./App.css";
import { useCallback, useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import WaveForm from "./WaveForm"; import WaveForm from "./WaveForm";
const App = () => { const App = () => {
const [audioUrl, setAudioUrl] = useState(), const [analyzerData, setAnalyzerData] = useState(null),
[analyzerData, setAnalyzerData] = useState(null),
[bounce, setBounce] = useState(''), [bounce, setBounce] = useState(''),
[json, setJson] = useState({}), [json, setJson] = useState({}),
[currentVolume, setCurrentVolume] = useState(0.5), [currentVolume, setCurrentVolume] = useState(0.5),
@ -80,14 +79,13 @@ const App = () => {
useEffect(() => { useEffect(() => {
loadData() loadData()
loadListeners() loadListeners()
setAudioUrl('/stream.mp3')
audioAnalyzer() audioAnalyzer()
const inter = setInterval(() => { const inter = setInterval(() => {
loadData() loadData()
loadListeners() loadListeners()
}, (Math.floor(Math.random() * 20) + 10) * 1000) }, (Math.floor(Math.random() * 20) + 10) * 1000)
return () => clearInterval(inter) return () => clearInterval(inter)
}, []) }, [audioElmRef.current])
useEffect(() => { useEffect(() => {
if (audioElmRef.current && audioElmRef.current.volume !== currentVolume && currentVolume >= 0 && currentVolume <= 1) { if (audioElmRef.current && audioElmRef.current.volume !== currentVolume && currentVolume >= 0 && currentVolume <= 1) {
audioElmRef.current.volume = currentVolume audioElmRef.current.volume = currentVolume
@ -120,7 +118,7 @@ const App = () => {
<button onClick={() => setMuted(true)}>Mute 🔇</button> <button onClick={() => setMuted(true)}>Mute 🔇</button>
} }
</div> </div>
<audio src={audioUrl} ref={audioElmRef} volume={currentVolume} preload={"none"} muted={muted} /> <audio src={"/stream.mp3"} ref={audioElmRef} volume={currentVolume} preload={"none"} muted={muted} controls={"none"} />
</> </>
) )
} }