Skip to content

Commit 5910103

Browse files
aveladjoeyparrish
authored andcommitted
perf: Only set the timers on UITextDisplayer when there are cues (#8114)
1 parent 55ddcf0 commit 5910103

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/text/ui_text_displayer.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ shaka.text.UITextDisplayer = class {
170170
this.cues_.push(cue);
171171
}
172172
}
173+
if (this.cues_.length) {
174+
this.configureCaptionsTimer_();
175+
}
173176

174177
this.updateCaptions_();
175178
}
@@ -232,6 +235,9 @@ shaka.text.UITextDisplayer = class {
232235
// displaying if removed (say, due to the user changing languages).
233236
const forceUpdate = oldNumCues > this.cues_.length;
234237
this.updateCaptions_(forceUpdate);
238+
if (!this.cues_.length) {
239+
this.configureCaptionsTimer_();
240+
}
235241

236242
return true;
237243
}
@@ -259,11 +265,15 @@ shaka.text.UITextDisplayer = class {
259265
*/
260266
configureCaptionsTimer_() {
261267
if (this.captionsTimer_) {
262-
const captionsUpdatePeriod = this.config_ ?
263-
this.config_.captionsUpdatePeriod : 0.25;
264-
const updateTime = captionsUpdatePeriod /
265-
Math.max(1, Math.abs(this.video_.playbackRate));
266-
this.captionsTimer_.tickEvery(updateTime);
268+
if (this.cues_.length) {
269+
const captionsUpdatePeriod = this.config_ ?
270+
this.config_.captionsUpdatePeriod : 0.25;
271+
const updateTime = captionsUpdatePeriod /
272+
Math.max(1, Math.abs(this.video_.playbackRate));
273+
this.captionsTimer_.tickEvery(updateTime);
274+
} else {
275+
this.captionsTimer_.stop();
276+
}
267277
}
268278
}
269279

0 commit comments

Comments
 (0)