Skip to content

Commit

Permalink
fix: Prevent bad calls to MediaSource.endOfStream (#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 #5070
  • Loading branch information
martinstark authored and joeyparrish committed Apr 26, 2023
1 parent eb6f792 commit ba6988f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,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 ba6988f

Please sign in to comment.