]> cat aescling's git repositories - mastodon.git/commitdiff
Fix hiding video breaking playback
authorThibaut Girka <thib@sitedethib.com>
Wed, 4 Nov 2020 14:12:06 +0000 (15:12 +0100)
committerThibG <thib@sitedethib.com>
Wed, 4 Nov 2020 17:53:39 +0000 (18:53 +0100)
Also make the video player code closer to upstream

app/javascript/flavours/glitch/features/video/index.js

index d22bc1d56a23307ded21f499f7a3dc504168b841..870812856911435dcc8ce566b7a7b2ba53fb7627 100644 (file)
@@ -281,9 +281,9 @@ class Video extends React.PureComponent {
 
   togglePlay = () => {
     if (this.state.paused) {
-      this.video.play();
+      this.setState({ paused: false }, () => this.video.play());
     } else {
-      this.video.pause();
+      this.setState({ paused: true }, () => this.video.pause());
     }
   }
 
@@ -381,13 +381,16 @@ class Video extends React.PureComponent {
   }
 
   toggleMute = () => {
-    this.video.muted = !this.video.muted;
-    this.setState({ muted: this.video.muted });
+    const muted = !this.video.muted;
+
+    this.setState({ muted }, () => {
+      this.video.muted = muted;
+    });
   }
 
   toggleReveal = () => {
     if (this.state.revealed) {
-      this.video.pause();
+      this.setState({ paused: true });
     }
 
     if (this.props.onToggleVisibility) {
@@ -475,13 +478,6 @@ class Video extends React.PureComponent {
       return (<div className={computedClass} ref={this.setPlayerRef} tabindex={0}></div>);
     }
 
-    let warning;
-    if (sensitive) {
-      warning = <FormattedMessage id='status.sensitive_warning' defaultMessage='Sensitive content' />;
-    } else {
-      warning = <FormattedMessage id='status.media_hidden' defaultMessage='Media hidden' />;
-    }
-
     let preload;
 
     if (this.props.currentTime || fullscreen || dragging) {
@@ -492,6 +488,14 @@ class Video extends React.PureComponent {
       preload = 'none';
     }
 
+    let warning;
+
+    if (sensitive) {
+      warning = <FormattedMessage id='status.sensitive_warning' defaultMessage='Sensitive content' />;
+    } else {
+      warning = <FormattedMessage id='status.media_hidden' defaultMessage='Media hidden' />;
+    }
+
     return (
       <div
         className={computedClass}