Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2400 issue - add configuration for browsers with bug on addCue method #2401

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/API.md
Expand Up @@ -58,6 +58,7 @@
- [`abrController`](#abrcontroller)
- [`timelineController`](#timelinecontroller)
- [`enableWebVTT`](#enablewebvtt)
- [`forceTextTrackCue`](#forceTextTrackCue)
- [`enableCEA708Captions`](#enablecea708captions)
- [`captionsTextTrack1Label`](#captionstexttrack1label)
- [`captionsTextTrack1LanguageCode`](#captionstexttrack1languagecode)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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`)
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
19 changes: 13 additions & 6 deletions src/controller/timeline-controller.js
Expand Up @@ -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);
}
}
}
}
Expand Down