Open source CapCut alternative.
TypeScript
fix(site): preview playback stop checks, held frames, and skim handoff
David Lecff16e870494
diff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsxindex d3d076c8..b43580fc 100644--- a/site/src/cut/components/Timeline.tsx+++ b/site/src/cut/components/Timeline.tsx@@ -670,7 +670,12 @@ export function Timeline() {const r = scrollEl?.getBoundingClientRect();const inside =!!p && !!r && p.x >= r.left && p.x <= r.right && p.y >= r.top && p.y <= r.bottom;- setSkim(inside ? Math.max(0, timeAt(p.x)) : null);+ // Resuming playback while the menu was up (Space) hands the picture+ // back to the playhead; re-arming the skimmer then would freeze every+ // DOM surface on the held frame while the canvas plays on.+ setSkim(+ inside && !useEditor.getState().playing ? Math.max(0, timeAt(p.x)) : null,+ );};// eslint-disable-next-line react-hooks/exhaustive-deps -- timeAt reads live refs}, [frameMenu]);diff --git a/site/src/cut/hooks/usePlayback.ts b/site/src/cut/hooks/usePlayback.tsindex 0e64b7a9..d23ac807 100644--- a/site/src/cut/hooks/usePlayback.ts+++ b/site/src/cut/hooks/usePlayback.ts@@ -167,10 +167,14 @@ class Engine {this.used.add(src);const st = sourceTimeOf(span.clip, t);src.want(st, playing);- if (src.failed) return MISSING_FRAME;+ // A failed source that already decoded frames keeps showing the nearest+ // one it holds — a transient blip (a network drop, a signed URL mid+ // re-mint) reads as a held frame, and only a source with nothing at all+ // to show goes missing.const frame = src.frameAt(st);- if (!frame) return PENDING_FRAME;- return { kind: "ready", image: frame.image, width: frame.width, height: frame.height };+ if (frame)+ return { kind: "ready", image: frame.image, width: frame.width, height: frame.height };+ return src.failed ? MISSING_FRAME : PENDING_FRAME;}/** Open and start the decoders for clips about to arrive — on track 0 and@@ -436,25 +440,25 @@ class Engine {// Ask for the master's picture before clearing. A clip nothing has decoded// yet answers `pending`, and clearing on the strength of that would black// the frame out for as long as the file takes to open — the strobe this- // whole design exists to remove. Leave what is on screen, stay dirty, and- // paint when there is something to paint.+ // whole design exists to remove. Leave what is on screen and stay dirty;+ // the clock, the audio, and the stop checks below still run, so a slow+ // open can't freeze the playhead or carry playback past a stop mark.const masterFrame = master ? this.frameFor(master, t, playing) : MISSING_FRAME;- if (masterFrame.kind === "pending") {- this.warm(t, playing);+ const pendingMaster = masterFrame.kind === "pending";+ const fadeGain = this.projectFadeGain(t, total);+ if (pendingMaster) {this.dirty = true;- return;+ } else {+ this.comp.clear();+ if (master) this.drawTrackZero(master, spans, t, playing, masterFrame);+ this.drawOverlays(t, playing);+ // The subject-mask pass reads the canvas as it stands beneath it, then+ // publishes the matte the DOM's front subject-masked elements read.+ this.comp.subjectMatteProvider = (at) => this.behind.clipMatteOf(this.canvas, at);+ this.behind.draw(this.canvas, s.overlays, s.assets, t);+ this.comp.drawProjectFade(fadeGain);}- this.comp.clear();- if (master) this.drawTrackZero(master, spans, t, playing, masterFrame);- this.drawOverlays(t, playing);- // The subject-mask pass reads the canvas as it stands beneath it, then- // publishes the matte the DOM's front subject-masked elements read.- this.comp.subjectMatteProvider = (at) => this.behind.clipMatteOf(this.canvas, at);- this.behind.draw(this.canvas, s.overlays, s.assets, t);- const fadeGain = this.projectFadeGain(t, total);- this.comp.drawProjectFade(fadeGain);-// Decoders for what is about to arrive, and the ones nothing needs closed.this.warm(t, playing);this.pool.evict();diff --git a/site/src/cut/lib/frameSource.ts b/site/src/cut/lib/frameSource.tsindex 6f6da9ce..c3529e6c 100644--- a/site/src/cut/lib/frameSource.ts+++ b/site/src/cut/lib/frameSource.ts@@ -301,6 +301,10 @@ export class ClipFrameSource {// A real jump: drop the walk and fetch the one frame. Newest ask wins, so// a fast drag decodes where it stopped rather than everywhere it crossed.this.stopStream();+ // The jump also starts a new walk story. A finished flag left over from+ // the old walk would pin playback to the seeked frame on resume: the+ // ring covers it, so no walk would restart until the frame aged out.+ this.streamDone = false;this.wanted = t;void this.pumpSeek();}diff --git a/site/src/cut/lib/store.ts b/site/src/cut/lib/store.tsindex 353de139..b3727d93 100644--- a/site/src/cut/lib/store.ts+++ b/site/src/cut/lib/store.ts@@ -3244,6 +3244,11 @@ export const useEditor = create<EditorState>((baseSet, get, api) => {const from = Math.max(0, Math.min(total, start));const to = Math.max(from + 0.05, Math.min(total, end));setPlayhead(from);+ // Starting playback drops the skimmer, same as setPlaying: while the+ // cut plays, the playhead owns the picture everywhere — a skim left+ // standing would freeze the DOM surfaces on one frame while the canvas+ // runs.+ setSkim(null);set({ playing: true, previewStopAt: to });},setPublish: (patch) => set((s) => ({ publish: { ...s.publish, ...patch } })),