Skip to content

Commit

Permalink
fix(player): initial seek on live:dvr should not go to edge
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Nov 6, 2023
1 parent 8b9fa4b commit f1837ad
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions packages/vidstack/src/core/state/media-state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,17 @@ export class MediaStateManager extends MediaPlayerController {

setTimeout(() => this._resetTracking(), 0);

const { paused, playing, seeking, ended } = this.$state;
const {
paused,
playing,
live,
liveSyncPosition,
seekableEnd,
started,
currentTime,
seeking,
ended,
} = this.$state;

paused.set(false);
playing.set(true);
Expand All @@ -466,18 +476,17 @@ export class MediaStateManager extends MediaPlayerController {
return;
}

if (live() && !started() && currentTime() === 0) {
const end = liveSyncPosition() ?? seekableEnd() - 2;
if (Number.isFinite(end)) this._media.$provider()!.currentTime = end;
}

this['started'](event);
}

['started'](event: Event) {
const { started, live, liveSyncPosition, seekableEnd } = this.$state;

const { started } = this.$state;
if (!started()) {
if (live()) {
const end = liveSyncPosition() ?? seekableEnd() - 2;
if (Number.isFinite(end)) this._media.$provider()!.currentTime = end;
}

started.set(true);
this._handle(this.createEvent('started', { trigger: event }));
}
Expand Down

0 comments on commit f1837ad

Please sign in to comment.