From 59ef54a158e14da2f7c6ab04e1fd9409bf63c6f0 Mon Sep 17 00:00:00 2001 From: Nyanmisaka Date: Fri, 7 Oct 2022 06:09:02 +0800 Subject: [PATCH] fix: Fix choppy HLS startup (#4553) Clearing the buffer seems to be not enough for this case. This avoids the choppy video start on HLS fMP4 playback. Tested with Chrome 106 & Edge 106. Closes #4516 --- lib/media/media_source_engine.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index 22edd671a0..f61e7b3edc 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -674,10 +674,17 @@ shaka.media.MediaSourceEngine = class { const textOffset = (reference.startTime || 0) - (mediaStartTime || 0); this.textSequenceModeOffset_.resolve(textOffset); - // Finally, clear the buffer. + // Clear the buffer. await this.enqueueOperation_( contentType, () => this.remove_(contentType, 0, this.mediaSource_.duration)); + + // Finally, flush the buffer in case of choppy video start on HLS fMP4. + if (contentType == ContentType.VIDEO) { + await this.enqueueOperation_( + contentType, + () => this.flush_(contentType)); + } } // Now switch to sequence mode and fall through to our normal operations.