From 3af100c94381895f7f176899f415ffcc8b219c2f Mon Sep 17 00:00:00 2001 From: Moshe Maor Date: Thu, 4 Jan 2024 16:58:49 +0200 Subject: [PATCH] fix(SUP-39894): fix bug in seekToLiveEdge (#747) Co-authored-by: Moshe Maor --- .../html5/media-source/adapters/native-adapter.ts | 14 ++++---------- .../media-source/base-media-source-adapter.ts | 4 ++++ src/player.ts | 5 ++++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/engines/html5/media-source/adapters/native-adapter.ts b/src/engines/html5/media-source/adapters/native-adapter.ts index 2a90fdad1..a487eb5c3 100644 --- a/src/engines/html5/media-source/adapters/native-adapter.ts +++ b/src/engines/html5/media-source/adapters/native-adapter.ts @@ -122,8 +122,6 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { private _waitingEventTriggered: boolean = false; - private _wasCurrentTimeSetSuccessfully!: boolean; - private _segmentDuration: number = 0; private _startTimeOfDvrWindowInterval: number | undefined; @@ -337,7 +335,6 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { * @returns {Promise} - The loaded data */ public load(startTime?: number): Promise<{tracks: Track[]}> { - this._wasCurrentTimeSetSuccessfully = false; this._maybeSetDrmPlayback(); if (!this._loadPromise) { this._loadPromise = new Promise<{tracks: Track[]}>((resolve, reject) => { @@ -541,9 +538,11 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { this._handleLiveDurationChange(); } }; - if (!this.isLive()) { - this._setStartTime(startTime); + + if (startTime !== undefined && startTime > -1) { + this._videoElement.currentTime = startTime; } + if (this._videoElement.textTracks.length > 0) { parseTracksAndResolve(); } else { @@ -556,7 +555,6 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { if (typeof startTime === 'number' && startTime > -1) { this._videoElement.currentTime = startTime; } - this._wasCurrentTimeSetSuccessfully = true; } private _onTimeUpdate(): void { @@ -1267,10 +1265,6 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { return this._videoElement.duration === Infinity; } - public isOnLiveEdge(): boolean { - return this._wasCurrentTimeSetSuccessfully ? super.isOnLiveEdge() : false; - } - /** * Handling live duration change (as safari doesn't trigger durationchange event on live playback) * @function _handleLiveDurationChange diff --git a/src/engines/html5/media-source/base-media-source-adapter.ts b/src/engines/html5/media-source/base-media-source-adapter.ts index 23ffd802c..a532dbd94 100644 --- a/src/engines/html5/media-source/base-media-source-adapter.ts +++ b/src/engines/html5/media-source/base-media-source-adapter.ts @@ -224,6 +224,10 @@ export default class BaseMediaSourceAdapter extends FakeEventTarget implements I } public isOnLiveEdge(): boolean { + if(this.getSegmentDuration()===0){ + //If no segment duration, we cannot estimate live edge + return true; + } return this.liveDuration - this._videoElement.currentTime <= this.getSegmentDuration() * CURRENT_OR_NEXT_SEGMENT_COUNT; } // eslint-disable-next-line diff --git a/src/player.ts b/src/player.ts index 5e0058b47..a93afc96e 100644 --- a/src/player.ts +++ b/src/player.ts @@ -2247,7 +2247,10 @@ export default class Player extends FakeEventTarget { if (!this._firstPlay) { return outOfDvr; } else { - return !!this.src && !this.isOnLiveEdge(); + return !!this.src && !this.isOnLiveEdge() + // Live video can be set with explicit start time,(e.g. startOver) + // in that case we don't want to move to the liveEdge + && this._sources.startTime === undefined; } } return false;