From 819861a4671163b5e3fedd5cf689a3524b23cc2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Thu, 24 Oct 2024 20:29:36 +0200 Subject: [PATCH] chore: Unify getBuffered_ behaviour in MediaSourceEngine to avoid issues (#7496) --- lib/media/media_source_engine.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index 4d9053c955..ab0ca83347 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -653,8 +653,7 @@ shaka.media.MediaSourceEngine = class { * @return {?number} The timestamp in seconds, or null if nothing is buffered. */ bufferStart(contentType) { - if (this.reloadingMediaSource_ || - !Object.keys(this.sourceBuffers_).length) { + if (!Object.keys(this.sourceBuffers_).length) { return null; } const ContentType = shaka.util.ManifestParserUtils.ContentType; @@ -672,7 +671,7 @@ shaka.media.MediaSourceEngine = class { * @return {?number} The timestamp in seconds, or null if nothing is buffered. */ bufferEnd(contentType) { - if (this.reloadingMediaSource_) { + if (!Object.keys(this.sourceBuffers_).length) { return null; } const ContentType = shaka.util.ManifestParserUtils.ContentType; @@ -692,9 +691,6 @@ shaka.media.MediaSourceEngine = class { * @return {boolean} */ isBuffered(contentType, time) { - if (this.reloadingMediaSource_) { - return false; - } const ContentType = shaka.util.ManifestParserUtils.ContentType; if (contentType == ContentType.TEXT) { return this.textEngine_.isBuffered(time); @@ -713,9 +709,6 @@ shaka.media.MediaSourceEngine = class { * @return {number} The amount of time buffered ahead in seconds. */ bufferedAheadOf(contentType, time) { - if (this.reloadingMediaSource_) { - return 0; - } const ContentType = shaka.util.ManifestParserUtils.ContentType; if (contentType == ContentType.TEXT) { return this.textEngine_.bufferedAheadOf(time); @@ -736,9 +729,9 @@ shaka.media.MediaSourceEngine = class { const info = { total: this.reloadingMediaSource_ ? [] : TimeRangesUtils.getBufferedInfo(this.video_.buffered), - audio: this.reloadingMediaSource_ ? [] : + audio: TimeRangesUtils.getBufferedInfo(this.getBuffered_(ContentType.AUDIO)), - video: this.reloadingMediaSource_ ? [] : + video: TimeRangesUtils.getBufferedInfo(this.getBuffered_(ContentType.VIDEO)), text: [], }; @@ -761,6 +754,9 @@ shaka.media.MediaSourceEngine = class { * @private */ getBuffered_(contentType) { + if (this.reloadingMediaSource_) { + return null; + } try { return this.sourceBuffers_[contentType].buffered; } catch (exception) {