From e85009de325c9da803df90ed37f9ef9c70788fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Tue, 22 Jun 2021 01:00:58 +0200 Subject: [PATCH] Fix: Fix clearing buffer when requested for already-selected variant (#3477) Close: #3450 --- lib/media/streaming_engine.js | 8 +++++--- lib/player.js | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index 57908079b3..3f66455be2 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -317,8 +317,10 @@ shaka.media.StreamingEngine = class { * @param {shaka.extern.Variant} variant * @param {boolean=} clearBuffer * @param {number=} safeMargin + * @param {boolean=} force + * If true, reload the variant even if it did not change. */ - switchVariant(variant, clearBuffer = false, safeMargin = 0) { + switchVariant(variant, clearBuffer = false, safeMargin = 0, force = false) { this.currentVariant_ = variant; if (!this.startupComplete_) { @@ -329,12 +331,12 @@ shaka.media.StreamingEngine = class { if (variant.video) { this.switchInternal_( variant.video, /* clearBuffer= */ clearBuffer, - /* safeMargin= */ safeMargin, /* force= */ false); + /* safeMargin= */ safeMargin, /* force= */ force); } if (variant.audio) { this.switchInternal_( variant.audio, /* clearBuffer= */ clearBuffer, - /* safeMargin= */ safeMargin, /* force= */ false); + /* safeMargin= */ safeMargin, /* force= */ force); } } diff --git a/lib/player.js b/lib/player.js index e76730c689..323045b092 100644 --- a/lib/player.js +++ b/lib/player.js @@ -4968,6 +4968,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget { const currentVariant = this.streamingEngine_.getCurrentVariant(); if (variant == currentVariant) { shaka.log.debug('Variant already selected.'); + // If you want to clear the buffer, we force to reselect the same variant + if (clearBuffer) { + this.streamingEngine_.switchVariant(variant, clearBuffer, safeMargin, + /* force= */ true); + } return; }