From c77cd301c8ab8e5fbd5ffe887bdd36064f4f2fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Mon, 16 Nov 2026 17:20:32 +0000 Subject: [PATCH] fix(studio): a long audio file from outside the project is never decoded for its waveform (#7961) --- .../src/hooks/useRenderClipContent.test.ts | 21 +++++++++++++++++++ .../studio/src/hooks/useRenderClipContent.ts | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/studio/src/hooks/useRenderClipContent.test.ts b/packages/studio/src/hooks/useRenderClipContent.test.ts index 53794f9368..205c2b35f3 100644 --- a/packages/studio/src/hooks/useRenderClipContent.test.ts +++ b/packages/studio/src/hooks/useRenderClipContent.test.ts @@ -190,6 +190,27 @@ describe("useRenderClipContent", () => { if (isValidElement(content)) expect(content.type).toBe(AudioWaveform); }); + it("decodes a file from outside the project only when it is short and its length is known", () => { + const remote = (sourceDuration?: number) => + renderClipContent({ + id: "talk", + tag: "audio", + start: 0, + duration: 4, + track: 1, + src: "https://cdn.example.com/talk.mp3", + sourceDuration, + }); + const audioUrlOf = (content: ReactNode) => + isValidElement<{ audioUrl: string; waveformUrl?: string }>(content) + ? [content.props.audioUrl, content.props.waveformUrl] + : null; + + expect(audioUrlOf(remote(180))).toEqual(["https://cdn.example.com/talk.mp3", undefined]); + expect(audioUrlOf(remote(62 * 60))).toEqual(["", undefined]); + expect(audioUrlOf(remote())).toEqual(["", undefined]); + }); + it("routes root-relative iframe media back through the active project", () => { usePlayerStore.setState({ thumbnailMode: "adaptive" }); const resolvedRootMedia = `${window.location.origin}/assets/clip.mp4`; diff --git a/packages/studio/src/hooks/useRenderClipContent.ts b/packages/studio/src/hooks/useRenderClipContent.ts index 21479d2d54..4e311e86fd 100644 --- a/packages/studio/src/hooks/useRenderClipContent.ts +++ b/packages/studio/src/hooks/useRenderClipContent.ts @@ -25,6 +25,7 @@ import { import { usePlayerStore } from "../player/store/playerStore"; import { thumbnailRevisionOf } from "../player/store/thumbnailSlice"; import { effectiveThumbnailMode } from "../player/lib/thumbnailPolicy"; +import { fitsBeatAnalysis } from "../utils/timelineInspector"; export function normalizeCompositionSrc( compSrc: string, @@ -84,8 +85,9 @@ function renderAudioClip( ? buildProjectApiPath(pid, `/waveform/${encodedRelative}`) : undefined; const { start, end } = trimFractions(el); + const serverPeaksOrShortFile = waveformUrl !== undefined || fitsBeatAnalysis(el); const waveform = createElement(AudioWaveform, { - audioUrl, + audioUrl: serverPeaksOrShortFile ? audioUrl : "", waveformUrl, label: "", labelColor,