diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index bab68e038e..5ed1e5eecf 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -391,7 +391,22 @@ shaka.media.MediaSourceEngine = class { } } 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',