Skip to content

Commit

Permalink
Fix: Fix clearing buffer when requested for already-selected variant (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
Álvaro Velad Galván authored Jun 21, 2021
1 parent f7facc0 commit e85009d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand All @@ -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);
}
}

Expand Down
5 changes: 5 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit e85009d

Please sign in to comment.