From ece8713462fd3d937660e1c291e605f4a22beef8 Mon Sep 17 00:00:00 2001 From: Yuval keidar Date: Sun, 13 Oct 2019 09:52:34 +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.js | 19 +++++++++++++------ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/API.md b/docs/API.md index b8345546312..e792f48464d 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.js b/src/controller/timeline-controller.js index 4f6f49cf19b..2e0ea223579 100644 --- a/src/controller/timeline-controller.js +++ b/src/controller/timeline-controller.js @@ -290,16 +290,23 @@ class TimelineController extends EventHandler { } // Add cues and trigger event with success true. cues.forEach(cue => { + const addTextTrackCue = (track, cue) => { + const textTrackCue = new window.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.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); + } } } }