From c32bf839c11557cac527ca5f181d1ce39fc80974 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 11 Jan 2019 16:44:45 +0100 Subject: [PATCH] Fix captions in HTTP fallback --- client/src/assets/player/peertube-player.ts | 8 ++++++++ client/src/assets/player/peertube-videojs-plugin.ts | 5 +++++ client/src/assets/player/settings-menu-item.ts | 13 +++++++++++++ 3 files changed, 26 insertions(+) diff --git a/client/src/assets/player/peertube-player.ts b/client/src/assets/player/peertube-player.ts index e0e063838..2de6d7fef 100644 --- a/client/src/assets/player/peertube-player.ts +++ b/client/src/assets/player/peertube-player.ts @@ -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 + }) } // ############################################################################ diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts index 4a280b7ef..e9fb90c61 100644 --- a/client/src/assets/player/peertube-videojs-plugin.ts +++ b/client/src/assets/player/peertube-videojs-plugin.ts @@ -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 diff --git a/client/src/assets/player/settings-menu-item.ts b/client/src/assets/player/settings-menu-item.ts index 698f4627a..2a3460ae5 100644 --- a/client/src/assets/player/settings-menu-item.ts +++ b/client/src/assets/player/settings-menu-item.ts @@ -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) })