From 69c6b1ca6d3ad9505b7378c2b8c3504cb4ccf6e3 Mon Sep 17 00:00:00 2001 From: Moshe Maor Date: Mon, 15 Jan 2024 17:08:54 +0200 Subject: [PATCH] Moshe Changes --- .../media-source/adapters/native-adapter.js | 42 ++++++++++++++----- .../media-source/base-media-source-adapter.js | 4 ++ src/player.js | 5 ++- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/engines/html5/media-source/adapters/native-adapter.js b/src/engines/html5/media-source/adapters/native-adapter.js index 5c9c5043f..9c5121002 100644 --- a/src/engines/html5/media-source/adapters/native-adapter.js +++ b/src/engines/html5/media-source/adapters/native-adapter.js @@ -120,10 +120,12 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { _waitingEventTriggered: ?boolean = false; - _wasCurrentTimeSetSuccessfully: boolean; - _segmentDuration: number = 0; + _startTimeOfDvrWindowInterval: IntervalID; + + _startTimeOfDvrWindow: number = 0; + /** * A counter to track the number of attempts to recover from media error * @type {number} @@ -253,6 +255,7 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { this._config = Utils.Object.mergeDeep({}, defaultConfig, this._config); this._progressiveSources = config.progressiveSources; this._liveEdge = 0; + this._setStarTimeOfDvrWindowInterval(); } /** @@ -327,7 +330,6 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { * @returns {Promise} - The loaded data */ load(startTime: ?number): Promise { - this._wasCurrentTimeSetSuccessfully = false; this._maybeSetDrmPlayback(); if (!this._loadPromise) { this._loadPromise = new Promise((resolve, reject) => { @@ -531,8 +533,8 @@ 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(); @@ -546,7 +548,6 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { if (typeof startTime === 'number' && startTime > -1) { this._videoElement.currentTime = startTime; } - this._wasCurrentTimeSetSuccessfully = true; } _onTimeUpdate(): void { @@ -637,6 +638,7 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { this._startTimeAttach = NaN; this._videoDimensions = null; this._clearHeartbeatTimeout(); + clearInterval(this._startTimeOfDvrWindowInterval); if (this._liveDurationChangeInterval) { clearInterval(this._liveDurationChangeInterval); this._liveDurationChangeInterval = null; @@ -1241,10 +1243,6 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { return this._videoElement.duration === Infinity; } - isOnLiveEdge(): boolean { - return this._wasCurrentTimeSetSuccessfully ? super.isOnLiveEdge() : false; - } - /** * Handling live duration change (as safari doesn't trigger durationchange event on live playback) * @function _handleLiveDurationChange @@ -1287,7 +1285,7 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { * @returns {Number} - start time of DVR window. * @public */ - getStartTimeOfDvrWindow(): number { + _getStartTimeOfDvrWindow(): number { if (this.isLive() && this._videoElement.seekable.length) { return this._videoElement.seekable.start(0); } else { @@ -1295,6 +1293,28 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { } } + getStartTimeOfDvrWindow() { + return this._startTimeOfDvrWindow; + } + + _setStarTimeOfDvrWindowInterval() { + const intervalTime = 1000; + this._startTimeOfDvrWindowInterval = setInterval(() => { + //get Segment duration + const duration = this._segmentDuration; + if ( + !this._waitingEventTriggered && //not in wait + this._getStartTimeOfDvrWindow() && //value is not Zero + duration && //Duration exist + Math.abs(this._getStartTimeOfDvrWindow() - this._startTimeOfDvrWindow) <= duration * 2 //Gap is less than twice the duration + ) { + this._startTimeOfDvrWindow += intervalTime / 1000; + } else { + this._startTimeOfDvrWindow = this._getStartTimeOfDvrWindow(); + } + }, intervalTime); + } + getDrmInfo(): ?PKDrmDataObject { return this._drmHandler ? this._drmHandler.getDrmInfo() : null; } diff --git a/src/engines/html5/media-source/base-media-source-adapter.js b/src/engines/html5/media-source/base-media-source-adapter.js index dc3d9b722..d6da8e2f8 100644 --- a/src/engines/html5/media-source/base-media-source-adapter.js +++ b/src/engines/html5/media-source/base-media-source-adapter.js @@ -221,6 +221,10 @@ export default class BaseMediaSourceAdapter extends FakeEventTarget implements I } 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; } diff --git a/src/player.js b/src/player.js index 921a1d5b5..7a1b5f0ac 100644 --- a/src/player.js +++ b/src/player.js @@ -2257,7 +2257,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;