From b8f630c643b2b24babb7666a2b261265dbfd64fd Mon Sep 17 00:00:00 2001 From: terencecho <3916587+terencecho@users.noreply.github.com> Date: Fri, 13 Nov 2026 19:18:24 +0000 Subject: [PATCH] fix(core): a looping preview keeps playing when a scene reloads during a hold for data (#7659) * fix(core): a looping preview keeps playing when a scene reloads during a hold for data A Studio preview unloads scenes far from the playhead. On a long film, the loop's wrap back to the start lands while the first scene is reloading: the film holds for its video, then the scene swap re-seeks with keepPlaying. The seek read the held film as paused, dropped the hold and parked the film at the start, so the loop stopped after its second pass. A seek that keeps playing now counts a hold for data as playing. Co-Authored-By: Claude Opus 5.5 * refactor(core): name the playing-or-held check and drop history from its test comment Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- .../core/src/runtime/init.buffering.test.ts | 19 +++++++++++++++++++ packages/core/src/runtime/init.ts | 7 ++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/core/src/runtime/init.buffering.test.ts b/packages/core/src/runtime/init.buffering.test.ts index f70b604c59..84ee600405 100644 --- a/packages/core/src/runtime/init.buffering.test.ts +++ b/packages/core/src/runtime/init.buffering.test.ts @@ -283,6 +283,25 @@ it("a pause while buffering stays paused once the track is ready", () => { expect(states.at(-1)).toEqual({ isPlaying: false, buffering: false }); }); +// A Studio preview reloading a far scene re-seeks with keepPlaying. When that lands while the film is held +// for data, the hold must survive it and the film plays on. +it("a seek that keeps playing during a hold for data plays on once the track is ready", () => { + const mark = document.createElement("meta"); + mark.name = STUDIO_PREVIEW_MARK_META; + document.head.append(mark); + const { voiceReady, states, playFor } = playPodcast(0, "video"); + + playFor(0.5); + expect(states.at(-1)).toEqual({ isPlaying: true, buffering: true }); + window.__player!.seek(0, { keepPlaying: true }); + voiceReady.value = 4; + playFor(1); + + mark.remove(); + expect(window.__player!.getTime()).toBeGreaterThan(0.5); + expect(states.at(-1)).toEqual({ isPlaying: true, buffering: false }); +}); + afterEach(() => { window.__hfRuntimeTeardown?.(); vi.restoreAllMocks(); diff --git a/packages/core/src/runtime/init.ts b/packages/core/src/runtime/init.ts index 70ed796f07..fb7616702b 100644 --- a/packages/core/src/runtime/init.ts +++ b/packages/core/src/runtime/init.ts @@ -3231,6 +3231,7 @@ export function initSandboxRuntimeModular(): void { } }; let bufferingFor: HTMLMediaElement[] = []; + const playingOrHeldForData = () => clock.isPlaying() || bufferingFor.length > 0; let keepLateMedia = false; const preloadNearPlayhead = ( el: HTMLMediaElement, @@ -4989,8 +4990,8 @@ export function initSandboxRuntimeModular(): void { const applySeek = (quantized: number, options?: { keepPlaying?: boolean }) => { webAudio.stopAll(); clock.detachAudioSource(); - const wasPlaying = clock.isPlaying(); - if (wasPlaying) clock.pause(); + const wasPlaying = playingOrHeldForData(); + if (clock.isPlaying()) clock.pause(); clock.seek(quantized); state.currentTime = clock.now(); state.isPlaying = false; @@ -5160,7 +5161,7 @@ export function initSandboxRuntimeModular(): void { state.nativeMediaSyncDisabled || isExportRenderDrivingFrames() || window.__HF_EXPORT_RENDER_SEEK_CONFIG || - (options?.keepPlaying && clock.isPlaying()) + (options?.keepPlaying && playingOrHeldForData()) ) { previewSeek?.cancel(); pausedFrames.clear();