Skip to content

Commit

Permalink
add comments for duplicated cues check
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioribeiro committed May 2, 2017
1 parent 06610e2 commit 4ff21ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/controller/timeline-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ class TimelineController extends EventHandler {
WebVTTParser.parse(payload, this.initPTS, vttCCs, frag.cc, function (cues) {
// Add cues and trigger event with success true.
cues.forEach(cue => {
// 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 (!textTracks[frag.trackId].cues.getCueById(cue.id)) {
textTracks[frag.trackId].addCue(cue);
}
Expand Down
3 changes: 3 additions & 0 deletions src/utils/webvtt-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ const WebVTTParser = {

cue.startTime += cueOffset - localTime;
cue.endTime += cueOffset - localTime;

// Create a unique hash id for a cue based on start/end times and text.
// This helps timeline-controller to avoid showing repeated captions.
cue.id = hash(cue.startTime) + hash(cue.endTime) + hash(cue.text);

// Fix encoding of special characters. TODO: Test with all sorts of weird characters.
Expand Down

0 comments on commit 4ff21ec

Please sign in to comment.