Try to fix auto play on apple devices
authorChocobozzz <me@florianbigard.com>
Mon, 11 May 2020 15:48:25 +0000 (17:48 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 11 May 2020 15:48:56 +0000 (17:48 +0200)
client/src/assets/player/peertube-player-manager.ts
client/src/assets/player/peertube-plugin.ts
client/src/assets/player/webtorrent/webtorrent-plugin.ts

index 61da6a4cb6ea69050120df23e601ee52dd67ed3c..5ebc247f2d4a29937f3c4e320231d001c221d8a6 100644 (file)
@@ -187,7 +187,7 @@ export class PeertubePlayerManager {
   ): videojs.PlayerOptions {
     const commonOptions = options.common
 
-    let autoplay = commonOptions.autoplay
+    let autoplay = this.getAutoPlayValue(commonOptions.autoplay)
     let html5 = {}
 
     const plugins: VideoJSPluginOptions = {
@@ -232,9 +232,7 @@ export class PeertubePlayerManager {
         ? commonOptions.muted
         : undefined, // Undefined so the player knows it has to check the local storage
 
-      autoplay: autoplay === true
-        ? this.getAutoPlayValue()
-        : autoplay,
+      autoplay: this.getAutoPlayValue(autoplay),
 
       poster: commonOptions.poster,
       inactivityTimeout: commonOptions.inactivityTimeout,
@@ -510,9 +508,15 @@ export class PeertubePlayerManager {
     })
   }
 
-  private static getAutoPlayValue () {
+  private static getAutoPlayValue (autoplay: any) {
+    if (autoplay !== true) return autoplay
+
+    const isIOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform)
     const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
 
+    // Giving up with iOS
+    if (isIOS) return false
+
     // We have issues with autoplay and Safari.
     // any that tries to play using auto mute seems to work
     if (isSafari) return 'any'
index 5085f7f86b758832ea9b19e371cceb0ebf055b77..a5a706420c6b146ac17aa66140e794e441f37de1 100644 (file)
@@ -45,7 +45,7 @@ class PeerTubePlugin extends Plugin {
 
     this.savedInactivityTimeout = player.options_.inactivityTimeout
 
-    if (options.autoplay === true) this.player.addClass('vjs-has-autoplay')
+    if (options.autoplay) this.player.addClass('vjs-has-autoplay')
 
     this.player.on('autoplay-failure', () => {
       this.player.removeClass('vjs-has-autoplay')
index cb3deacc6f6074684ad84a672afa21f57450d1c6..a894a90f56f262ff51304a970910ef74e4bcc5bb 100644 (file)
@@ -417,7 +417,7 @@ class WebTorrentPlugin extends Plugin {
   private initializePlayer () {
     this.buildQualities()
 
-    if (this.autoplay === true) {
+    if (this.autoplay) {
       this.player.posterImage.hide()
 
       return this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime })