Skip to content

Commit e1d34a5

Browse files
committed
fix: avoid filtering out VTTCues with matching ids
1 parent 408bba3 commit e1d34a5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/utils/texttrack-utils.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ export function sendAddTrackEvent(track: TextTrack, videoEl: HTMLMediaElement) {
1313
videoEl.dispatchEvent(event);
1414
}
1515

16+
function containsCue(track: TextTrack, cue: VTTCue) {
17+
if (!track.cues) {
18+
return false;
19+
}
20+
21+
for (let i = 0; i < track.cues.length; i++) {
22+
const cueInTextTrack = track.cues[i] as VTTCue;
23+
if (
24+
cueInTextTrack.startTime === cue.startTime &&
25+
cueInTextTrack.endTime === cue.endTime &&
26+
cueInTextTrack.text === cue.text
27+
) {
28+
return true;
29+
}
30+
}
31+
32+
return false;
33+
}
34+
1635
export function addCueToTrack(track: TextTrack, cue: VTTCue) {
1736
// Sometimes there are cue overlaps on segmented vtts so the same
1837
// cue can appear more than once in different vtt files.
@@ -21,7 +40,8 @@ export function addCueToTrack(track: TextTrack, cue: VTTCue) {
2140
if (mode === 'disabled') {
2241
track.mode = 'hidden';
2342
}
24-
if (track.cues && !track.cues.getCueById(cue.id)) {
43+
44+
if (track.cues && !containsCue(track, cue)) {
2545
try {
2646
track.addCue(cue);
2747
if (!track.cues.getCueById(cue.id)) {

0 commit comments

Comments
 (0)