Skip to content
Merged
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
10 changes: 5 additions & 5 deletions packages/core/src/runtime/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1796,11 +1796,7 @@ export function initSandboxRuntimeModular(): void {
if (!rawEl.paused) {
clock.attachAudioSource({ el: rawEl, compositionStart: start, mediaStart });
foundActive = true;
} else if (
!rawEl.error &&
rawEl.networkState !== HTMLMediaElement.NETWORK_NO_SOURCE &&
rawEl.readyState < HTMLMediaElement.HAVE_FUTURE_DATA
) {
} else if (!rawEl.error && rawEl.readyState < HTMLMediaElement.HAVE_FUTURE_DATA) {
// Audio is buffering — freeze visuals at last known position
// instead of falling through to monotonic (which runs ahead).
clock.attachAudioSource({ currentTimeSeconds: state.currentTime });
Expand Down Expand Up @@ -1887,6 +1883,10 @@ export function initSandboxRuntimeModular(): void {
state.currentTime = 0;
seekTimelineAndAdapters(0);
}
} else {
const rootEl = resolveRootCompositionElement();
const declaredDur = Number(rootEl?.getAttribute("data-duration") ?? 0);
if (declaredDur > 0) clock.setDuration(declaredDur);
}
if (tl) tl.pause();
if (!clock.play()) return;
Expand Down
18 changes: 16 additions & 2 deletions packages/core/src/runtime/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,26 @@ export function syncRuntimeMedia(params: {
const offsetJumped = !firstTickOfClip && Math.abs(offset - prevOffset!) > 0.5;
const catastrophicDrift = drift > 3;
const hardSync = drift > 0.5 && (firstTickOfClip || offsetJumped || catastrophicDrift);
// Playing video elements use the browser's native decoder pipeline for
// timing. Seeking a playing video resets the decoder, causing a ~150ms
// freeze while it re-buffers — during which the monotonic clock advances,
// creating a perpetual seek→freeze→drift→seek stutter loop. Skip strict
// and force sync for playing videos; only hard sync (>0.5s) warrants
// the decoder-reset cost.
const isPlayingVideo = el.tagName === "VIDEO" && !el.paused;
// Only apply strict sync when offset has stabilized (not growing).
// During initial buffering, offset grows ~16ms/tick as the timeline
// advances while media stays at 0. Accumulated drift from pause/play
// toggling shows up as a stable, non-zero offset (delta near 0).
const offsetStabilized = prevOffset !== undefined && Math.abs(offset - prevOffset) < 0.004;
let strictSync = false;
if (!hardSync && !firstTickOfClip && offsetStabilized && drift > STRICT_DRIFT_THRESHOLD) {
if (
!isPlayingVideo &&
!hardSync &&
!firstTickOfClip &&
offsetStabilized &&
drift > STRICT_DRIFT_THRESHOLD
) {
const samples = (strictDriftSamples.get(el) ?? 0) + 1;
strictDriftSamples.set(el, samples);
if (samples >= STRICT_REQUIRED_SAMPLES) {
Expand All @@ -214,7 +227,8 @@ export function syncRuntimeMedia(params: {
} else if (drift <= STRICT_DRIFT_THRESHOLD) {
strictDriftSamples.set(el, 0);
}
if (hardSync || strictSync || (params.forceSync && drift > 0.02)) {
const forceSync = !isPlayingVideo && params.forceSync && drift > 0.02;
if (hardSync || strictSync || forceSync) {
try {
el.currentTime = relTime;
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions packages/studio/src/player/components/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ export const Player = forwardRef<HTMLIFrameElement, PlayerProps>(
assetOverlayVisible && !shaderTransitionLoading && !showCompositionOverlay;

useEffect(() => {
onCompositionLoadingChange?.(showCompositionOverlay);
}, [onCompositionLoadingChange, showCompositionOverlay]);
onCompositionLoadingChange?.(showCompositionOverlay || showAssetOverlay);
}, [onCompositionLoadingChange, showCompositionOverlay, showAssetOverlay]);

return (
<div
Expand Down
Loading