From 2f653f132b98499e5a28c7b3884021d47596fbee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Wed, 24 Apr 2024 17:22:14 +0200 Subject: [PATCH] fix: Don't update captions when video is paused (#6474) This avoids wasting processing resources when it is not necessary --- lib/text/ui_text_displayer.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/text/ui_text_displayer.js b/lib/text/ui_text_displayer.js index 1ac4df3813..1b138e719a 100644 --- a/lib/text/ui_text_displayer.js +++ b/lib/text/ui_text_displayer.js @@ -72,7 +72,9 @@ shaka.text.UITextDisplayer = class { /** @private {shaka.util.Timer} */ this.captionsTimer_ = new shaka.util.Timer(() => { - this.updateCaptions_(); + if (!this.video_.paused) { + this.updateCaptions_(); + } }).tickEvery(updatePeriod); /** @@ -93,6 +95,10 @@ shaka.text.UITextDisplayer = class { this.updateCaptions_(/* forceUpdate= */ true); }); + this.eventManager_.listen(this.video_, 'seeking', () => { + this.updateCaptions_(/* forceUpdate= */ true); + }); + // From: https://html.spec.whatwg.org/multipage/media.html#dom-video-videowidth // Whenever the natural width or natural height of the video changes // (including, for example, because the selected video track was changed),