audio load
Signed-off-by: ale <ale@manalejandro.com>
This commit is contained in:
parent
5f1a81abb1
commit
685d928215
10
src/App.js
10
src/App.js
@ -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"} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user