Skip to content

Commit

Permalink
fix(SUP-39894): fix bug in seekToLiveEdge (#747)
Browse files Browse the repository at this point in the history
Co-authored-by: Moshe Maor <moshe.mar@kaltura.com>
  • Loading branch information
MosheMaorKaltura and Moshe Maor authored Jan 4, 2024
1 parent ccee6f6 commit 3af100c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
14 changes: 4 additions & 10 deletions src/engines/html5/media-source/adapters/native-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -337,7 +335,6 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
* @returns {Promise<Object>} - 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) => {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/engines/html5/media-source/base-media-source-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3af100c

Please sign in to comment.