Skip to content

Commit

Permalink
fix: Fix media source duration when using sequence mode (shaka-projec…
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Jan 9, 2023
1 parent 6c16df8 commit 1762267
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/media/media_source_engine.js
Expand Up @@ -658,6 +658,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.
Expand Down Expand Up @@ -701,7 +703,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) {
Expand All @@ -713,6 +715,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) {
Expand Down

0 comments on commit 1762267

Please sign in to comment.