From 64389a274a2d11039cd3d543bec847e1a672cccc Mon Sep 17 00:00:00 2001 From: Martin Stark <901824+martinstark@users.noreply.github.com> Date: Thu, 9 Mar 2023 01:12:33 +0100 Subject: [PATCH] fix: Prevent bad calls to MediaSource.endOfStream (#5071) This prevents the streaming engine from calling MediaSource.endOfStream when media source's readyState is "closed". It's not valid to close a stream that is already closed. See: https://developer.mozilla.org/en-US/docs/Web/API/MediaSource/endOfStream#exceptions Fixes #5070 --- lib/media/media_source_engine.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index bab68e038e..3145de578a 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -1041,8 +1041,10 @@ shaka.media.MediaSourceEngine = class { async endOfStream(reason) { await this.enqueueBlockingOperation_(() => { // If endOfStream() has already been called on the media source, - // don't call it again. - if (this.ended()) { + // don't call it again. Also do not call if readyState is + // 'closed' (not attached to video element) since it is not a + // valid operation. + if (this.ended() || this.mediaSource_.readyState === 'closed') { return; } // Tizen won't let us pass undefined, but it will let us omit the