Skip to content

Commit

Permalink
fix(FEC-12686): Web - When changing the caption from RUS to JAP in th…
Browse files Browse the repository at this point in the history
…e middle of the video, all of the past caption are shown at once

When adding active cues - advance the cue index, but don't add active cues if they are are expired
When removing active cues - use filter instead of splicing in a loop, which caused some cues to not be removed.
Reset cue index on text track selection to force recalculation of the cue index
  • Loading branch information
SivanA-Kaltura authored Jan 19, 2023
1 parent f22b4c7 commit 97f97e6
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/track/external-captions-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,11 @@ class ExternalCaptionsHandler extends FakeEventTarget {
if (!currentTime) {
return false;
}
let hadRemoved = false;
for (let activeTextCuesIndex = 0; activeTextCuesIndex < this._activeTextCues.length; activeTextCuesIndex++) {
const cue = this._activeTextCues[activeTextCuesIndex];
if (currentTime < cue.startTime || cue.endTime < currentTime) {
this._activeTextCues.splice(activeTextCuesIndex, 1);
hadRemoved = true;
}
}

const updatedActiveTextCues = this._activeTextCues.filter(cue => cue.startTime < currentTime && currentTime < cue.endTime);
const hadRemoved = this._activeTextCues.length !== updatedActiveTextCues.length;
this._activeTextCues = updatedActiveTextCues;

return hadRemoved;
}

Expand All @@ -469,7 +466,9 @@ class ExternalCaptionsHandler extends FakeEventTarget {
let hadAdded = false;
const cues = this._textTrackModel[track.language].cues;
while (this._externalCueIndex < cues.length && currentTime > cues[this._externalCueIndex].startTime) {
this._activeTextCues.push(cues[this._externalCueIndex]);
if (currentTime < cues[this._externalCueIndex].endTime) {
this._activeTextCues.push(cues[this._externalCueIndex]);
}
this._externalCueIndex++;
hadAdded = true;
}
Expand All @@ -495,7 +494,6 @@ class ExternalCaptionsHandler extends FakeEventTarget {
break;
}
}
this._externalCueIndex = i;
return true;
}
return false;
Expand Down Expand Up @@ -576,6 +574,7 @@ class ExternalCaptionsHandler extends FakeEventTarget {
this._isTextTrackActive = true;
ExternalCaptionsHandler._logger.debug('External text track changed', textTrack);
this._activeTextCues = [];
this._externalCueIndex = 0;
this.dispatchEvent(new FakeEvent(CustomEventType.TEXT_CUE_CHANGED, {cues: this._activeTextCues}));
this._eventManager.listen(this._player, Html5EventType.TIME_UPDATE, () => this._handleCaptionOnTimeUpdate(textTrack));
}
Expand Down

0 comments on commit 97f97e6

Please sign in to comment.