From 3807e146e4e910d16b452b896d4faaf52a314160 Mon Sep 17 00:00:00 2001 From: Sai Teja Date: Tue, 12 Aug 2025 03:55:52 +0530 Subject: [PATCH] feat(playback): restart from beginning when play pressed at end of timeline (Fixes #536) (#542) --- apps/web/src/stores/playback-store.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/apps/web/src/stores/playback-store.ts b/apps/web/src/stores/playback-store.ts index feea0f46..a92cb530 100644 --- a/apps/web/src/stores/playback-store.ts +++ b/apps/web/src/stores/playback-store.ts @@ -82,6 +82,24 @@ export const usePlaybackStore = create((set, get) => ({ speed: 1.0, play: () => { + const state = get(); + + const actualContentDuration = useTimelineStore + .getState() + .getTotalDuration(); + const effectiveDuration = + actualContentDuration > 0 ? actualContentDuration : state.duration; + + if (effectiveDuration > 0) { + const fps = useProjectStore.getState().activeProject?.fps ?? 30; + const frameOffset = 1 / fps; + const endThreshold = Math.max(0, effectiveDuration - frameOffset); + + if (state.currentTime >= endThreshold) { + get().seek(0); + } + } + set({ isPlaying: true }); startTimer(get); },