diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index 9940caee53..082dcc05d3 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -682,6 +682,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. @@ -725,7 +727,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) { @@ -737,6 +739,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) {