Skip to content

Commit

Permalink
fix(player): allow seeking directly to end
Browse files Browse the repository at this point in the history
closes #1178
  • Loading branch information
mihar-22 committed Mar 20, 2024
1 parent 4bd90a8 commit 20cc205
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
15 changes: 9 additions & 6 deletions packages/vidstack/src/components/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,15 @@ export class MediaPlayer
peek(() => {
if (!this._provider) return;

const boundTime = Math.min(
Math.max(seekableStart() + 0.1, time + clipStartTime()),
seekableEnd() - 0.1,
);

if (Number.isFinite(boundTime)) this._provider.setCurrentTime(boundTime);
const clippedTime = time + clipStartTime(),
isEnd = Math.floor(clippedTime) === Math.floor(seekableEnd()),
boundTime = isEnd
? seekableEnd()
: Math.min(Math.max(seekableStart() + 0.1, clippedTime), seekableEnd() - 0.1);

if (Number.isFinite(boundTime)) {
this._provider.setCurrentTime(boundTime);
}
});
});
}
Expand Down
12 changes: 7 additions & 5 deletions packages/vidstack/src/core/state/media-request-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ export class MediaRequestManager extends MediaPlayerController implements MediaR

['media-seek-request'](event: RE.MediaSeekRequestEvent) {
const { seekableStart, seekableEnd, ended, canSeek, live, userBehindLiveEdge, clipStartTime } =
this.$state;
this.$state,
seekTime = event.detail;

if (ended()) this._request._replaying = true;

Expand All @@ -710,10 +711,11 @@ export class MediaRequestManager extends MediaPlayerController implements MediaR
this._request._seeking = false;
this._request._queue._delete(key);

const boundTime = Math.min(
Math.max(seekableStart() + 0.1, event.detail + clipStartTime()),
seekableEnd() - 0.1,
);
const clippedTime = seekTime + clipStartTime(),
isEnd = Math.floor(clippedTime) === Math.floor(seekableEnd()),
boundTime = isEnd
? seekableEnd()
: Math.min(Math.max(seekableStart() + 0.1, clippedTime), seekableEnd() - 0.1);

if (!Number.isFinite(boundTime) || !canSeek()) return;

Expand Down

0 comments on commit 20cc205

Please sign in to comment.