Skip to content

Commit 95a3dad

Browse files
committed
fix(player): clipping broken
closes #1382
1 parent 0917752 commit 95a3dad

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

packages/vidstack/src/core/api/player-state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ export const mediaState = new State<MediaState>({
134134
},
135135
get seekableStart() {
136136
const start = getTimeRangesStart(this.seekable) ?? 0;
137-
return Math.max(0, start - this.clipStartTime);
137+
return Math.max(0, Math.abs(start - this.clipStartTime));
138138
},
139139
get seekableEnd() {
140-
const end = this.canPlay ? getTimeRangesEnd(this.seekable) ?? Infinity : 0;
140+
const end = this.canPlay ? (getTimeRangesEnd(this.seekable) ?? Infinity) : 0;
141141
return this.clipEndTime > 0
142142
? Math.max(this.clipEndTime, Math.max(0, end - this.clipStartTime))
143143
: end;

packages/vidstack/src/core/state/media-state-manager.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -686,18 +686,25 @@ export class MediaStateManager extends MediaPlayerController {
686686
const provider = peek(this.#media.$provider);
687687
if (!provider) return;
688688

689-
const { ended, seekableStart, clipStartTime, clipEndTime, realCurrentTime, duration } =
690-
this.$state;
689+
const {
690+
ended,
691+
seekableStart,
692+
clipStartTime,
693+
clipEndTime,
694+
currentTime,
695+
realCurrentTime,
696+
duration,
697+
} = this.$state;
691698

692699
const shouldReset =
700+
ended() ||
693701
realCurrentTime() < clipStartTime() ||
694702
(clipEndTime() > 0 && realCurrentTime() >= clipEndTime()) ||
695-
Math.abs(realCurrentTime() - duration()) < 0.1 ||
696-
ended();
703+
Math.abs(currentTime() - duration()) < 0.1;
697704

698705
if (shouldReset) {
699706
this.dispatch('media-seek-request', {
700-
detail: (clipStartTime() > 0 ? 0 : seekableStart()) + 0.1,
707+
detail: seekableStart(),
701708
trigger,
702709
});
703710
}

0 commit comments

Comments
 (0)