From 169c11c3979901561a67d16c5f8ae15c3aae8fde Mon Sep 17 00:00:00 2001 From: Yuval keidar Date: Sun, 13 Oct 2019 10:11:43 +0300 Subject: [PATCH] fix #2400 issue - add configuration for browsers with bug on addCue method add new configuration forceTextTrackCue to enable captions on problematic OS such as LG SDK 2, which has bug on their addCue method with different structure it won't add caption at all. --- docs/API.md | 10 ++++++++++ src/config.ts | 2 ++ src/controller/timeline-controller.ts | 19 +++++++++++++------ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/API.md b/docs/API.md index 43b7da05cc3..b9e26154d9e 100644 --- a/docs/API.md +++ b/docs/API.md @@ -58,6 +58,7 @@ - [`abrController`](#abrcontroller) - [`timelineController`](#timelinecontroller) - [`enableWebVTT`](#enablewebvtt) + - [`forceTextTrackCue`](#forcetexttrackcue) - [`enableCEA708Captions`](#enablecea708captions) - [`captionsTextTrack1Label`](#captionstexttrack1label) - [`captionsTextTrack1LanguageCode`](#captionstexttrack1languagecode) @@ -342,6 +343,7 @@ Configuration parameters could be provided to hls.js upon instantiation of `Hls` fpsController: FPSController, timelineController: TimelineController, enableWebVTT: true, + forceTextTrackCue: false, enableCEA708Captions: true, stretchShortVideoTrack: false, maxAudioFramesDrift: 1, @@ -831,6 +833,14 @@ whether or not to enable WebVTT captions on HLS parameter should be a boolean +### `forceTextTrackCue` + +(default: `false`) + +force use on text track cue for specific OS with bug on addCue method + +parameter should be a boolean + ### `enableCEA708Captions` (default: `true`) diff --git a/src/config.ts b/src/config.ts index efc8e27c7e1..ffa3546dc6d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -114,6 +114,7 @@ type TimelineControllerConfig = { cueHandler: any, // TODO(typescript-cues): Type once file is done enableCEA708Captions: boolean, enableWebVTT: boolean, + forceTextTrackCue: boolean, captionsTextTrack1Label: string, captionsTextTrack1LanguageCode: string, captionsTextTrack2Label: string, @@ -256,6 +257,7 @@ function timelineConfig (): TimelineControllerConfig { cueHandler: Cues, // used by timeline-controller enableCEA708Captions: true, // used by timeline-controller enableWebVTT: true, // used by timeline-controller + forceTextTrackCue: false, // used by timeline-controller captionsTextTrack1Label: 'English', // used by timeline-controller captionsTextTrack1LanguageCode: 'en', // used by timeline-controller captionsTextTrack2Label: 'Spanish', // used by timeline-controller diff --git a/src/controller/timeline-controller.ts b/src/controller/timeline-controller.ts index 17aa63a15f1..b92f2dec16a 100644 --- a/src/controller/timeline-controller.ts +++ b/src/controller/timeline-controller.ts @@ -288,16 +288,23 @@ class TimelineController extends EventHandler { } // Add cues and trigger event with success true. cues.forEach(cue => { + const addTextTrackCue = (track, cue) => { + const textTrackCue = new (window as any).TextTrackCue(cue.startTime, cue.endTime, cue.text); + textTrackCue.id = cue.id; + track.addCue(textTrackCue); + }; // Sometimes there are cue overlaps on segmented vtts so the same // cue can appear more than once in different vtt files. // This avoid showing duplicated cues with same timecode and text. if (!currentTrack.cues.getCueById(cue.id)) { - try { - currentTrack.addCue(cue); - } catch (err) { - const textTrackCue = new (window as any).TextTrackCue(cue.startTime, cue.endTime, cue.text); - textTrackCue.id = cue.id; - currentTrack.addCue(textTrackCue); + if (hls.config.forceTextTrackCue) { + addTextTrackCue(currentTrack, cue); + } else { + try { + currentTrack.addCue(cue); + } catch (err) { + addTextTrackCue(currentTrack, cue); + } } } }