Skip to content

Commit c1ee0fc

Browse files
author
Kevin
committed
fix: correct max value calculation for time control and improve playback logic
1 parent d4b01d4 commit c1ee0fc

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/leva-controls/Playback.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function Playback() {
2626
onChange: setTime,
2727
value: time ?? 0,
2828
min: 0,
29-
max: timespan,
29+
max: max([timespan - 1, 0]),
3030
step: 1,
3131
label: "Time",
3232
disabled: !timespan,
@@ -54,14 +54,21 @@ export function Playback() {
5454
const interval = setInterval(() => {
5555
const tb = now();
5656
const next =
57-
min([
58-
store.get(timeAtom) +
59-
max([1, store.get(speedAtom) * round((tb - ta) / frame)])!,
60-
store.get(lengthAtom),
57+
max([
58+
min([
59+
store.get(timeAtom) +
60+
max([1, store.get(speedAtom) * round((tb - ta) / frame)])!,
61+
store.get(lengthAtom) - 1,
62+
]),
63+
0,
6164
]) ?? 0;
6265
set({ time: next });
6366
setTime(next);
64-
if (next && next === store.get(lengthAtom) && !store.get(bufferingAtom)) {
67+
if (
68+
next &&
69+
next === store.get(lengthAtom) - 1 &&
70+
!store.get(bufferingAtom)
71+
) {
6572
setPlaying(false);
6673
}
6774
ta = tb;

0 commit comments

Comments
 (0)