av-merge: Fix error when switching qualities after endOfStream

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 <heckyel@hyperbola.info>
This commit is contained in:
James Taylor 2021-08-28 19:04:45 -07:00 committed by Jesús
parent 77fffee34f
commit 92bdbf072e
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766

View File

@ -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)