diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index 50ac6a7a55..5c6688504a 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -654,6 +654,8 @@ shaka.media.MediaSourceEngine = class { // into extracting a timestamp for us to align text segments in sequence // mode. + const duration = this.mediaSource_.duration; + // Timestamps can only be reliably extracted from video, not audio. // Packed audio formats do not have internal timestamps at all. // Prefer video for this when available. @@ -697,7 +699,7 @@ shaka.media.MediaSourceEngine = class { // Clear the buffer. await this.enqueueOperation_( contentType, - () => this.remove_(contentType, 0, this.mediaSource_.duration)); + () => this.remove_(contentType, 0, duration)); // Finally, flush the buffer in case of choppy video start on HLS fMP4. if (contentType == ContentType.VIDEO) { @@ -709,6 +711,10 @@ shaka.media.MediaSourceEngine = class { // Now switch to sequence mode and fall through to our normal operations. sourceBuffer.mode = SEQUENCE; + + // When we change the buffer mode the duration is lost, so we need to set + // it explicitly. + await this.setDuration(duration); } if (reference && this.sequenceMode_ && contentType != ContentType.TEXT) {