about summary refs log tree commit diff
path: root/app/javascript
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-08-25 02:13:40 +0200
committerGitHub <noreply@github.com>2019-08-25 02:13:40 +0200
commite72bac7576263445630926dd9992004ece7b73c4 (patch)
treeeeacf9a5a1a36da9df74a158e55869c3afc4e756 /app/javascript
parentaa6b5b42df7bcde08da6bc4d686a83b4533207df (diff)
Fix public page crash due to audio player, fix unpause in audio player (#11652)
Diffstat (limited to 'app/javascript')
-rw-r--r--app/javascript/mastodon/features/audio/index.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/app/javascript/mastodon/features/audio/index.js b/app/javascript/mastodon/features/audio/index.js
index 4f699ce70..b95860fcf 100644
--- a/app/javascript/mastodon/features/audio/index.js
+++ b/app/javascript/mastodon/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 });
     }
   }