Browse Source

Request video callback used for display refresh rate synchronization.

refactor/modularize
RUSHIL AMBARISH KADU 6 months ago
parent
commit
aa0fa618b9
  1. 18
      steps/src/main.js

18
steps/src/main.js

@ -521,12 +521,17 @@ saveSessionBtn.addEventListener("click", () => {
}); });
function videoFrameCallback(now, metadata) { function videoFrameCallback(now, metadata) {
// 'now' is a high-resolution timestamp provided by the browser
if (appState.lastVideoFrameTime > 0) {
const delta = now - appState.lastVideoFrameTime;
appState.videoFrameRenderTime = delta;
// If the video is no longer playing, stop the callback loop.
if (!appState.isPlaying || videoPlayer.paused) {
return;
} }
appState.lastVideoFrameTime = now;
// This is now the main animation driver during playback.
// It's perfectly synced with the video's frame presentation.
const currentTime = metadata.mediaTime;
const frameIndex = findRadarFrameIndexForTime(currentTime * 1000);
updateFrame(frameIndex, false); // Update radar, but don't seek video.
// Re-register the callback for the next frame to create a loop // Re-register the callback for the next frame to create a loop
videoPlayer.requestVideoFrameCallback(videoFrameCallback); videoPlayer.requestVideoFrameCallback(videoFrameCallback);
@ -685,8 +690,9 @@ playPauseBtn.addEventListener("click", () => {
appState.mediaTimeStart = videoPlayer.currentTime; appState.mediaTimeStart = videoPlayer.currentTime;
appState.lastSyncTime = appState.masterClockStart; appState.lastSyncTime = appState.masterClockStart;
videoPlayer.play(); videoPlayer.play();
videoPlayer.requestVideoFrameCallback(videoFrameCallback); // Start the high-precision loop
} }
requestAnimationFrame(animationLoop);
requestAnimationFrame(animationLoop); // Keep rAF for non-video sync (e.g. scrubbing)
} else { } else {
if (videoPlayer.src) videoPlayer.pause(); if (videoPlayer.src) videoPlayer.pause();
} }

Loading…
Cancel
Save