[Glitch] Fix public page crash due to audio player, fix unpause in audio player
Port e72bac7576
to glitch-soc
Signed-off-by: Thibaut Girka <thib@sitedethib.com>
This commit is contained in:
parent
3aeaf9b897
commit
84d4d75c91
|
@ -84,6 +84,7 @@ class Audio extends React.PureComponent {
|
||||||
|
|
||||||
if (this.wavesurfer) {
|
if (this.wavesurfer) {
|
||||||
this.wavesurfer.destroy();
|
this.wavesurfer.destroy();
|
||||||
|
this.loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wavesurfer = WaveSurfer.create({
|
const wavesurfer = WaveSurfer.create({
|
||||||
|
@ -100,8 +101,10 @@ class Audio extends React.PureComponent {
|
||||||
|
|
||||||
if (preload) {
|
if (preload) {
|
||||||
wavesurfer.load(src);
|
wavesurfer.load(src);
|
||||||
|
this.loaded = true;
|
||||||
} else {
|
} else {
|
||||||
wavesurfer.load(src, arrayOf(1, 0.5), null, duration);
|
wavesurfer.load(src, arrayOf(1, 0.5), null, duration);
|
||||||
|
this.loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
wavesurfer.on('ready', () => this.setState({ duration: Math.floor(wavesurfer.getDuration()) }));
|
wavesurfer.on('ready', () => this.setState({ duration: Math.floor(wavesurfer.getDuration()) }));
|
||||||
|
@ -116,15 +119,18 @@ class Audio extends React.PureComponent {
|
||||||
|
|
||||||
togglePlay = () => {
|
togglePlay = () => {
|
||||||
if (this.state.paused) {
|
if (this.state.paused) {
|
||||||
if (!this.props.preload) {
|
if (!this.props.preload && !this.loaded) {
|
||||||
this.wavesurfer.createBackend();
|
this.wavesurfer.createBackend();
|
||||||
this.wavesurfer.createPeakCache();
|
this.wavesurfer.createPeakCache();
|
||||||
this.wavesurfer.load(this.props.src);
|
this.wavesurfer.load(this.props.src);
|
||||||
|
this.loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.wavesurfer.play();
|
this.wavesurfer.play();
|
||||||
|
this.setState({ paused: false });
|
||||||
} else {
|
} else {
|
||||||
this.wavesurfer.pause();
|
this.wavesurfer.pause();
|
||||||
|
this.setState({ paused: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue