Fix captions in HTTP fallback

This commit is contained in:
Chocobozzz 2019-01-11 16:44:45 +01:00
parent f242c2e01e
commit c32bf839c1
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 26 additions and 0 deletions

View File

@ -254,6 +254,10 @@ function loadLocaleInVideoJS (serverUrl: string, videojs: any, locale: string) {
loadLocaleInVideoJS.cache[path] = json loadLocaleInVideoJS.cache[path] = json
return json return json
}) })
.catch(err => {
console.error('Cannot get player translations', err)
return undefined
})
} }
const completeLocale = getCompleteLocale(locale) const completeLocale = getCompleteLocale(locale)
@ -270,6 +274,10 @@ function getServerTranslations (serverUrl: string, locale: string) {
return fetch(path + '/server.json') return fetch(path + '/server.json')
.then(res => res.json()) .then(res => res.json())
.catch(err => {
console.error('Cannot get server translations', err)
return undefined
})
} }
// ############################################################################ // ############################################################################

View File

@ -620,6 +620,9 @@ class PeerTubePlugin extends Plugin {
this.player.src = this.savePlayerSrcFunction this.player.src = this.savePlayerSrcFunction
this.player.src(httpUrl) this.player.src(httpUrl)
// We changed the source, so reinit captions
this.initCaptions()
return this.tryToPlay(err => { return this.tryToPlay(err => {
if (err && done) return done(err) if (err && done) return done(err)
@ -720,6 +723,8 @@ class PeerTubePlugin extends Plugin {
default: this.defaultSubtitle === caption.language default: this.defaultSubtitle === caption.language
}, false) }, false)
} }
this.player.trigger('captionsChanged')
} }
// Thanks: https://github.com/videojs/video.js/issues/4460#issuecomment-312861657 // Thanks: https://github.com/videojs/video.js/issues/4460#issuecomment-312861657

View File

@ -48,6 +48,19 @@ class SettingsMenuItem extends MenuItem {
// Update on rate change // Update on rate change
player.on('ratechange', this.submenuClickHandler) 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() this.reset()
}, 0) }, 0)
}) })