From 84d4d75c91db62adb7f81ba6382f2f756898e6eb Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 25 Aug 2019 02:13:40 +0200 Subject: [PATCH] [Glitch] Fix public page crash due to audio player, fix unpause in audio player Port e72bac7576263445630926dd9992004ece7b73c4 to glitch-soc Signed-off-by: Thibaut Girka --- app/javascript/flavours/glitch/features/audio/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/javascript/flavours/glitch/features/audio/index.js b/app/javascript/flavours/glitch/features/audio/index.js index 1daf56bc1..bdd297d86 100644 --- a/app/javascript/flavours/glitch/features/audio/index.js +++ b/app/javascript/flavours/glitch/features/audio/index.js @@ -84,6 +84,7 @@ class Audio extends React.PureComponent { if (this.wavesurfer) { this.wavesurfer.destroy(); + this.loaded = false; } const wavesurfer = WaveSurfer.create({ @@ -100,8 +101,10 @@ class Audio extends React.PureComponent { if (preload) { wavesurfer.load(src); + this.loaded = true; } else { wavesurfer.load(src, arrayOf(1, 0.5), null, duration); + this.loaded = false; } wavesurfer.on('ready', () => this.setState({ duration: Math.floor(wavesurfer.getDuration()) })); @@ -116,15 +119,18 @@ class Audio extends React.PureComponent { togglePlay = () => { if (this.state.paused) { - if (!this.props.preload) { + if (!this.props.preload && !this.loaded) { this.wavesurfer.createBackend(); this.wavesurfer.createPeakCache(); this.wavesurfer.load(this.props.src); + this.loaded = true; } this.wavesurfer.play(); + this.setState({ paused: false }); } else { this.wavesurfer.pause(); + this.setState({ paused: true }); } }