Skip to content

Commit

Permalink
Merge pull request #2951 from jnatalzia/jnatz/ensure_min_id3_cue_dura…
Browse files Browse the repository at this point in the history
…tion

Require min cue duration of 0.25
  • Loading branch information
robwalch committed Aug 4, 2020
2 parents 02bacb6 + 2a951f3 commit 0476198
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/controller/id3-track-controller.js
Expand Up @@ -8,6 +8,8 @@ import ID3 from '../demux/id3';
import { logger } from '../utils/logger';
import { sendAddTrackEvent, clearCurrentCues, getClosestCue } from '../utils/texttrack-utils';

const MIN_CUE_DURATION = 0.25;

class ID3TrackController extends EventHandler {
constructor (hls) {
super(hls,
Expand Down Expand Up @@ -76,12 +78,11 @@ class ID3TrackController extends EventHandler {
if (!endTime) {
endTime = fragment.start + fragment.duration;
}
if (startTime === endTime) {
// Give a slight bump to the endTime if it's equal to startTime to avoid a SyntaxError in IE
endTime += 0.0001;
} else if (startTime > endTime) {
logger.warn('detected an id3 sample with endTime < startTime, adjusting endTime to (startTime + 0.25)');
endTime = startTime + 0.25;

const timeDiff = endTime - startTime;
if (timeDiff < MIN_CUE_DURATION) {
logger.warn(`detected an id3 sample with a duration of ${timeDiff}s. Adjusting to provide a duration of ${MIN_CUE_DURATION}`);
endTime += MIN_CUE_DURATION - timeDiff;
}

for (let j = 0; j < frames.length; j++) {
Expand Down

0 comments on commit 0476198

Please sign in to comment.