Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions apps/web/src/core/managers/playback-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,26 @@ export class PlaybackManager {
const maxTime = this.editor.timeline.getTotalDuration();

if (newTime >= maxTime) {
const shouldLoop =
this.editor.project.getActive()?.settings.loop === true &&
maxTime > ZERO_MEDIA_TIME;

if (shouldLoop) {
this.playbackStartWallTime = performance.now();
this.playbackStartTime = ZERO_MEDIA_TIME;
this.currentTime = ZERO_MEDIA_TIME;
this.notifySeek(ZERO_MEDIA_TIME);
this.dispatchSeekEvent(ZERO_MEDIA_TIME);
this.playbackTimer = requestAnimationFrame(this.updateTime);
return;
}

this.pause();
this.currentTime = maxTime;
this.notify();
this.notifySeek(maxTime);
this.dispatchSeekEvent(maxTime);
return;
this.notifySeek(maxTime);
this.dispatchSeekEvent(maxTime);
return;
}

this.currentTime = newTime;
Expand Down
28 changes: 27 additions & 1 deletion apps/web/src/preview/components/toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
FullScreenIcon,
PauseIcon,
PlayIcon,
RepeatIcon,
RepeatOffIcon,
} from "@hugeicons/core-free-icons";
import { UpdateProjectSettingsCommand } from "@/commands/project";
import { HugeiconsIcon } from "@hugeicons/react";
import { Separator } from "@/components/ui/separator";
import {
Expand All @@ -34,7 +37,10 @@ export function PreviewToolbar({
return (
<div className="grid grid-cols-[1fr_auto_1fr] items-center pb-3 pt-5 px-5">
<TimecodeDisplay />
<PlayPauseButton />
<div className="justify-self-center flex items-center gap-1">
<PlayPauseButton />
<LoopToggleButton />
</div>
<div className="justify-self-end flex items-center gap-2.5">
<ZoomSelect />
<Separator orientation="vertical" className="h-4" />
Expand Down Expand Up @@ -144,3 +150,23 @@ function PlayPauseButton() {
</Button>
);
}

function LoopToggleButton() {
const loop = useEditor((e) => e.project.getActive()?.settings.loop === true);

return (
<Button
type="button"
variant={loop ? "secondary" : "text"}
size="icon"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
aria-pressed={loop}
aria-label={loop ? "Disable loop playback" : "Enable loop playback"}
title={loop ? "Loop is on" : "Loop is off"}
onClick={() => {
new UpdateProjectSettingsCommand({ loop: !loop }).execute();
}}
>
<HugeiconsIcon icon={loop ? RepeatIcon : RepeatOffIcon} />
</Button>
);
}
5 changes: 5 additions & 0 deletions apps/web/src/project/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface TProjectSettings {
lastCustomCanvasSize?: TCanvasSize | null;
originalCanvasSize?: TCanvasSize | null;
background: TBackground;
/**
* When true, preview playback wraps back to the start of the timeline
* instead of pausing once the playhead reaches the end. Defaults to false.
*/
loop?: boolean;
}

export interface TTimelineViewState {
Expand Down