From 92bdbf072eebe6d85276e195936efff5b8d5f42c Mon Sep 17 00:00:00 2001 From: James Taylor Date: Sat, 28 Aug 2021 19:04:45 -0700 Subject: av-merge: Fix error when switching qualities after endOfStream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After the video has been buffered to the end and mediaSource.endOfStream() has been called, the close function would perform some closing operations on the sourceBuffers that gave InvalidStateError Signed-off-by: Jesús --- youtube/static/js/av-merge.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'youtube/static/js/av-merge.js') diff --git a/youtube/static/js/av-merge.js b/youtube/static/js/av-merge.js index f820927..1d5ada6 100644 --- a/youtube/static/js/av-merge.js +++ b/youtube/static/js/av-merge.js @@ -83,7 +83,8 @@ AVMerge.prototype.close = function() { this.audioStream.close(); this.timeUpdateEvt.remove(); this.seekingEvt.remove(); - this.mediaSource.endOfStream(); + if (this.mediaSource.readyState == 'open') + this.mediaSource.endOfStream(); } AVMerge.prototype.checkBothBuffers = function() { this.audioStream.checkBuffer(); @@ -199,9 +200,10 @@ Stream.prototype.close = function() { // Prevents appendSegment adding to buffer if request finishes // after closing this.closed = true; - this.sourceBuffer.abort(); - this.updateendEvt.remove(); + if (this.sourceBuffer.updating) + this.sourceBuffer.abort(); this.mediaSource.removeSourceBuffer(this.sourceBuffer); + this.updateendEvt.remove(); } Stream.prototype.appendSegment = function(segmentIdx, chunk) { if (this.closed) -- cgit v1.2.3