From 10b102d91adcc61f8a4b8709415bcc76a91f0e6e Mon Sep 17 00:00:00 2001 From: Bertrand Berthelot Date: Mon, 6 Sep 2021 15:08:44 +0200 Subject: [PATCH] Fix javascript errors on reset --- src/streaming/SourceBufferSink.js | 12 ++++++++---- src/streaming/controllers/BufferController.js | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/streaming/SourceBufferSink.js b/src/streaming/SourceBufferSink.js index fb5c42416d..d534590a0c 100644 --- a/src/streaming/SourceBufferSink.js +++ b/src/streaming/SourceBufferSink.js @@ -298,9 +298,11 @@ function SourceBufferSink(config) { const appendWindowStart = buffer.appendWindowStart; const appendWindowEnd = buffer.appendWindowEnd; - buffer.abort(); - buffer.appendWindowStart = appendWindowStart; - buffer.appendWindowEnd = appendWindowEnd; + if (buffer) { + buffer.abort(); + buffer.appendWindowStart = appendWindowStart; + buffer.appendWindowEnd = appendWindowEnd; + } resolve(); }); }); @@ -401,7 +403,9 @@ function SourceBufferSink(config) { appendQueue = []; if (mediaSource.readyState === 'open') { _waitForUpdateEnd(() => { - buffer.abort(); + if (buffer) { + buffer.abort(); + } resolve(); }); } else if (buffer && buffer.setTextTrack && mediaSource.readyState === 'ended') { diff --git a/src/streaming/controllers/BufferController.js b/src/streaming/controllers/BufferController.js index 6a7e4c6e96..6fb2090df0 100644 --- a/src/streaming/controllers/BufferController.js +++ b/src/streaming/controllers/BufferController.js @@ -284,12 +284,15 @@ function BufferController(config) { return; } + // Check if session has not been stopped in the meantime (while last segment was being appended) + if (!sourceBufferSink) return; + _updateBufferLevel(); isQuotaExceeded = false; appendedBytesInfo = e.chunk; - if (!appendedBytesInfo.endFragment) { + if (!appendedBytesInfo || !appendedBytesInfo.endFragment) { return; }