Audio: move useEffect's to bottom, remove unused code
This commit is contained in:
parent
6dddaea736
commit
cc27e46067
|
@ -102,44 +102,6 @@ const Audio: React.FC<IAudio> = (props) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (player.current) {
|
|
||||||
_setDimensions();
|
|
||||||
}
|
|
||||||
}, [player.current]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (audio.current) {
|
|
||||||
setVolume(audio.current.volume);
|
|
||||||
setMuted(audio.current.muted);
|
|
||||||
}
|
|
||||||
}, [audio.current]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (canvas.current && visualizer.current) {
|
|
||||||
visualizer.current.setCanvas(canvas.current);
|
|
||||||
}
|
|
||||||
}, [canvas.current, visualizer.current]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
window.addEventListener('scroll', handleScroll);
|
|
||||||
window.addEventListener('resize', handleResize, { passive: true });
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener('scroll', handleScroll);
|
|
||||||
window.removeEventListener('resize', handleResize);
|
|
||||||
|
|
||||||
if (!paused && audio.current && deployPictureInPicture) {
|
|
||||||
deployPictureInPicture('audio', _pack());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
_clear();
|
|
||||||
_draw();
|
|
||||||
}, [src, width, height, accentColor]);
|
|
||||||
|
|
||||||
const togglePlay = () => {
|
const togglePlay = () => {
|
||||||
if (!audioContext.current) {
|
if (!audioContext.current) {
|
||||||
_initAudioContext();
|
_initAudioContext();
|
||||||
|
@ -334,24 +296,6 @@ const Audio: React.FC<IAudio> = (props) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// const handleDownload = () => {
|
|
||||||
// fetch(src).then(res => res.blob()).then(blob => {
|
|
||||||
// const element = document.createElement('a');
|
|
||||||
// const objectURL = URL.createObjectURL(blob);
|
|
||||||
|
|
||||||
// element.setAttribute('href', objectURL);
|
|
||||||
// element.setAttribute('download', fileNameFromURL(src));
|
|
||||||
|
|
||||||
// document.body.appendChild(element);
|
|
||||||
// element.click();
|
|
||||||
// document.body.removeChild(element);
|
|
||||||
|
|
||||||
// URL.revokeObjectURL(objectURL);
|
|
||||||
// }).catch(err => {
|
|
||||||
// console.error(err);
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
|
|
||||||
const _renderCanvas = () => {
|
const _renderCanvas = () => {
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
if (!audio.current) return;
|
if (!audio.current) return;
|
||||||
|
@ -450,8 +394,47 @@ const Audio: React.FC<IAudio> = (props) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDuration = () => duration || props.duration || 0;
|
const getDuration = () => duration || props.duration || 0;
|
||||||
|
|
||||||
const progress = Math.min((currentTime / getDuration()) * 100, 100);
|
const progress = Math.min((currentTime / getDuration()) * 100, 100);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (player.current) {
|
||||||
|
_setDimensions();
|
||||||
|
}
|
||||||
|
}, [player.current]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (audio.current) {
|
||||||
|
setVolume(audio.current.volume);
|
||||||
|
setMuted(audio.current.muted);
|
||||||
|
}
|
||||||
|
}, [audio.current]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (canvas.current && visualizer.current) {
|
||||||
|
visualizer.current.setCanvas(canvas.current);
|
||||||
|
}
|
||||||
|
}, [canvas.current, visualizer.current]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.addEventListener('scroll', handleScroll);
|
||||||
|
window.addEventListener('resize', handleResize, { passive: true });
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('scroll', handleScroll);
|
||||||
|
window.removeEventListener('resize', handleResize);
|
||||||
|
|
||||||
|
if (!paused && audio.current && deployPictureInPicture) {
|
||||||
|
deployPictureInPicture('audio', _pack());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
_clear();
|
||||||
|
_draw();
|
||||||
|
}, [src, width, height, accentColor]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classNames('audio-player', { editable })}
|
className={classNames('audio-player', { editable })}
|
||||||
|
|
Loading…
Reference in New Issue