Skip to content

Commit

Permalink
fix: Prevent bad calls to MediaSource.endOfStream (shaka-project#5071)
Browse files Browse the repository at this point in the history
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 shaka-project#5070
  • Loading branch information
martinstark committed Mar 9, 2023
1 parent 6508f40 commit 64389a2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/media/media_source_engine.js
Expand Up @@ -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
Expand Down

0 comments on commit 64389a2

Please sign in to comment.