From 29a27cdb87bb3c36b3ddb917fadfaa473ddfe83a Mon Sep 17 00:00:00 2001 From: Martin Stark <901824+martinstark@users.noreply.github.com> Date: Tue, 14 Mar 2023 19:23:10 +0100 Subject: [PATCH] fix: mitigate uncaught type error in media_source_engine (#5069) Fixes #4903 --- lib/media/media_source_engine.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index 9aef7b1f7b..ced14a4160 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -375,7 +375,22 @@ shaka.media.MediaSourceEngine = class { shaka.media.Transmuxer.convertCodecs(contentType, mimeType); } const type = mimeType + this.config_.sourceBufferExtraFeatures; - const sourceBuffer = this.mediaSource_.addSourceBuffer(type); + + this.destroyer_.ensureNotDestroyed(); + + let sourceBuffer; + + try { + sourceBuffer = this.mediaSource_.addSourceBuffer(type); + } catch (exception) { + throw new shaka.util.Error( + shaka.util.Error.Severity.CRITICAL, + shaka.util.Error.Category.MEDIA, + shaka.util.Error.Code.MEDIA_SOURCE_OPERATION_THREW, + exception, + 'The mediaSource_ status was' + this.mediaSource_.readyState + + 'expected \'open\''); + } this.eventManager_.listen( sourceBuffer, 'error',