Fix captions in HTTP fallback
authorChocobozzz <me@florianbigard.com>
Fri, 11 Jan 2019 15:44:45 +0000 (16:44 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 14 Jan 2019 08:07:08 +0000 (09:07 +0100)
client/src/assets/player/peertube-player.ts
client/src/assets/player/peertube-videojs-plugin.ts
client/src/assets/player/settings-menu-item.ts

index e0e0638387f3a90ac0011250e071254c4b5057ba..2de6d7fefe4d75f4d6e2635105f23c913cc7f01d 100644 (file)
@@ -254,6 +254,10 @@ function loadLocaleInVideoJS (serverUrl: string, videojs: any, locale: string) {
         loadLocaleInVideoJS.cache[path] = json
         return json
       })
+      .catch(err => {
+        console.error('Cannot get player translations', err)
+        return undefined
+      })
   }
 
   const completeLocale = getCompleteLocale(locale)
@@ -270,6 +274,10 @@ function getServerTranslations (serverUrl: string, locale: string) {
 
   return fetch(path + '/server.json')
     .then(res => res.json())
+    .catch(err => {
+      console.error('Cannot get server translations', err)
+      return undefined
+    })
 }
 
 // ############################################################################
index 4a280b7efed111f6153011941697209e31705b09..e9fb90c61e2659265f98131a6c9d9a410aa35760 100644 (file)
@@ -620,6 +620,9 @@ class PeerTubePlugin extends Plugin {
     this.player.src = this.savePlayerSrcFunction
     this.player.src(httpUrl)
 
+    // We changed the source, so reinit captions
+    this.initCaptions()
+
     return this.tryToPlay(err => {
       if (err && done) return done(err)
 
@@ -720,6 +723,8 @@ class PeerTubePlugin extends Plugin {
         default: this.defaultSubtitle === caption.language
       }, false)
     }
+
+    this.player.trigger('captionsChanged')
   }
 
   // Thanks: https://github.com/videojs/video.js/issues/4460#issuecomment-312861657
index 698f4627a95525ce28eb987422064f652aa001cf..2a3460ae542b713be5403d2208e3a773bf92ec53 100644 (file)
@@ -48,6 +48,19 @@ class SettingsMenuItem extends MenuItem {
         // Update on rate change
         player.on('ratechange', this.submenuClickHandler)
 
+        if (subMenuName === 'CaptionsButton') {
+          // Hack to regenerate captions on HTTP fallback
+          player.on('captionsChanged', () => {
+            setTimeout(() => {
+              this.settingsSubMenuEl_.innerHTML = ''
+              this.settingsSubMenuEl_.appendChild(this.subMenu.menu.el_)
+              this.update()
+              this.bindClickEvents()
+
+            }, 0)
+          })
+        }
+
         this.reset()
       }, 0)
     })