Fix autoplay on Safari
authorChocobozzz <me@florianbigard.com>
Mon, 11 May 2020 15:20:23 +0000 (17:20 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 11 May 2020 15:48:56 +0000 (17:48 +0200)
client/src/assets/player/peertube-player-manager.ts

index 12e460f03b37f131f35fc5e17244a81a565e1216..61da6a4cb6ea69050120df23e601ee52dd67ed3c 100644 (file)
@@ -233,7 +233,7 @@ export class PeertubePlayerManager {
         : undefined, // Undefined so the player knows it has to check the local storage
 
       autoplay: autoplay === true
-        ? 'play' // Use 'any' instead of true to get notifier by videojs if autoplay fails
+        ? this.getAutoPlayValue()
         : autoplay,
 
       poster: commonOptions.poster,
@@ -509,6 +509,16 @@ export class PeertubePlayerManager {
       }
     })
   }
+
+  private static getAutoPlayValue () {
+    const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
+
+    // We have issues with autoplay and Safari.
+    // any that tries to play using auto mute seems to work
+    if (isSafari) return 'any'
+
+    return 'play'
+  }
 }
 
 // ############################################################################