Merge pull request #1793 from theprojectsomething/features/postload-captions

Preload TextTracks as per default video element
This commit is contained in:
Sam Potts 2020-04-23 22:03:45 +10:00 committed by GitHub
commit dbe618c644
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -133,8 +133,12 @@ const captions = {
});
// Turn off native caption rendering to avoid double captions
// Note: mode='hidden' forces a track to download. To ensure every track
// isn't downloaded at once, only 'showing' tracks should be reassigned
// eslint-disable-next-line no-param-reassign
if (track.mode === 'showing') {
track.mode = 'hidden';
}
// Add event listener for cue changes
on.call(this, track, 'cuechange', () => captions.updateCues.call(this));
@ -211,6 +215,14 @@ const captions = {
// Trigger event (not used internally)
triggerEvent.call(this, this.media, active ? 'captionsenabled' : 'captionsdisabled');
}
// Wait for the call stack to clear before setting mode='hidden'
// on the active track - forcing the browser to download it
setTimeout(() => {
if (active && this.captions.toggled) {
this.captions.currentTrackNode.mode = 'hidden';
}
});
},
// Set captions by track index