current play plause
Signed-off-by: ale <ale@manalejandro.com>
This commit is contained in:
parent
e2a47c22d0
commit
3f4753cf68
20
src/App.js
20
src/App.js
@ -13,9 +13,7 @@ const App = () => {
|
|||||||
[title, setTitle] = useState('Stream Radio'),
|
[title, setTitle] = useState('Stream Radio'),
|
||||||
[currentListeners, setCurrentListeners] = useState(0),
|
[currentListeners, setCurrentListeners] = useState(0),
|
||||||
[maxListeners, setMaxListeners] = useState(0),
|
[maxListeners, setMaxListeners] = useState(0),
|
||||||
[playPause, setPlayPause] = useState(false),
|
|
||||||
audioElmRef = useRef(null),
|
audioElmRef = useRef(null),
|
||||||
once = useRef(false),
|
|
||||||
audioAnalyzer = () => {
|
audioAnalyzer = () => {
|
||||||
const audioCtx = new (window.AudioContext || window.webkitAudioContext)(),
|
const audioCtx = new (window.AudioContext || window.webkitAudioContext)(),
|
||||||
analyzer = audioCtx.createAnalyser()
|
analyzer = audioCtx.createAnalyser()
|
||||||
@ -30,18 +28,6 @@ const App = () => {
|
|||||||
}
|
}
|
||||||
setAnalyzerData({ analyzer, bufferLength, dataArray })
|
setAnalyzerData({ analyzer, bufferLength, dataArray })
|
||||||
},
|
},
|
||||||
play = () => {
|
|
||||||
if (audioElmRef.current) {
|
|
||||||
audioElmRef.current.play()
|
|
||||||
setPlayPause(true)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
pause = () => {
|
|
||||||
if (audioElmRef.current) {
|
|
||||||
audioElmRef.current.pause()
|
|
||||||
setPlayPause(false)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
loadData = () => {
|
loadData = () => {
|
||||||
fetch('/stream.json').then(response => response.json()).then(json => {
|
fetch('/stream.json').then(response => response.json()).then(json => {
|
||||||
setJson(json)
|
setJson(json)
|
||||||
@ -115,9 +101,9 @@ const App = () => {
|
|||||||
<h4><p className="bounce"><a href={link} target="_blank" title={title} alt={title}>{bounce}</a></p></h4>
|
<h4><p className="bounce"><a href={link} target="_blank" title={title} alt={title}>{bounce}</a></p></h4>
|
||||||
<div>
|
<div>
|
||||||
<h2>Audio Controls</h2>
|
<h2>Audio Controls</h2>
|
||||||
{!playPause ?
|
{audioElmRef.current?.paused ?
|
||||||
<button onClick={play}>Play ⏯️</button> :
|
<button onClick={() => audioElmRef.current?.play()}>Play ⏯️</button> :
|
||||||
<button onClick={pause}>Pause ⏯️</button>
|
<button onClick={() => audioElmRef.current?.pause()}>Pause ⏯️</button>
|
||||||
}
|
}
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<button onClick={() => setCurrentVolume(currentVolume >= 0 && currentVolume <= 0.9 ? currentVolume + 0.1 : currentVolume)}>Volume Up 🔊</button>
|
<button onClick={() => setCurrentVolume(currentVolume >= 0 && currentVolume <= 0.9 ? currentVolume + 0.1 : currentVolume)}>Volume Up 🔊</button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user