Skip to content

Commit

Permalink
Fix a bug for VTT.js based rendering that causes cues not to be remov… (
Browse files Browse the repository at this point in the history
#4224)

* Fix a bug for VTT.js based rendering that causes cues not to be removed after switching to a different stream
  • Loading branch information
dsilhavy committed Jul 12, 2023
1 parent 520cfe5 commit e56b669
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/streaming/text/TextTracks.js
Expand Up @@ -449,7 +449,7 @@ function TextTracks(config) {
if (JSON.stringify(cue1[key]) !== JSON.stringify(cue2[key])) {
return false;
}
};
}
return true;
}

Expand Down Expand Up @@ -629,21 +629,25 @@ function TextTracks(config) {
WebVTT.processCues(window, [cue], vttCaptionContainer, cue.cueID);
} else if (cue.isActive && (cue.startTime > time || cue.endTime < time)) {
cue.isActive = false;
if (vttCaptionContainer) {
const divs = vttCaptionContainer.childNodes;
for (let i = 0; i < divs.length; ++i) {
if (divs[i].id === cue.cueID) {
vttCaptionContainer.removeChild(divs[i]);
--i;
}
}
}
_removeManualCue(cue);
}
})
}
}
}

function _removeManualCue(cue) {
if (vttCaptionContainer) {
const divs = vttCaptionContainer.childNodes;
for (let i = 0; i < divs.length; ++i) {
if (divs[i].id === cue.cueID) {
vttCaptionContainer.removeChild(divs[i]);
--i;
}
}
}
}

function disableManualTracks() {
const activeTracks = _getManualActiveTracks();

Expand Down Expand Up @@ -755,20 +759,33 @@ function TextTracks(config) {
}

function cueInRange(cue, start, end, strict = true) {
if (!cue) {
return false
}
return (isNaN(start) || (strict ? cue.startTime : cue.endTime) >= start) && (isNaN(end) || (strict ? cue.endTime : cue.startTime) <= end);
}

function deleteTrackCues(track, start, end, strict = true) {
if (track.cues) {
const cues = track.cues;
if (track && (track.cues || track.manualCueList)) {
const mode = track.cues && track.cues.length > 0 ? 'native' : 'custom';
const cues = mode === 'native' ? track.cues : track.manualCueList;

if (!cues || cues.length === 0) {
return;
}
const lastIdx = cues.length - 1;

for (let r = lastIdx; r >= 0; r--) {
if (cueInRange(cues[r], start, end, strict)) {
if (cues[r].onexit) {
cues[r].onexit();
if (mode === 'native') {
if (cues[r].onexit) {
cues[r].onexit();
}
track.removeCue(cues[r]);
} else {
_removeManualCue(cues[r]);
delete track.manualCueList[r]
}
track.removeCue(cues[r]);
}
}
}
Expand Down

0 comments on commit e56b669

Please sign in to comment.