fix: sync webcam preview playback speed

This commit is contained in:
Marcus Schiesser
2026-03-17 19:37:12 +08:00
parent 2fb5b3b574
commit e4263d4597
8 changed files with 106 additions and 7 deletions
+5 -1
View File
@@ -248,7 +248,11 @@ export function LaunchWindow() {
</button>
<button
className={`${hudIconBtnClasses} ${webcamEnabled ? "drop-shadow-[0_0_4px_rgba(74,222,128,0.4)]" : ""}`}
onClick={() => !recording && setWebcamEnabled(!webcamEnabled)}
onClick={() => {
if (!recording) {
void setWebcamEnabled(!webcamEnabled);
}
}}
disabled={recording}
title={webcamEnabled ? "Disable webcam" : "Enable webcam"}
>
@@ -968,6 +968,13 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
return;
}
const activeSpeedRegion =
speedRegions.find(
(region) =>
currentTime * 1000 >= region.startMs && currentTime * 1000 < region.endMs,
) ?? null;
webcamVideo.playbackRate = activeSpeedRegion ? activeSpeedRegion.speed : 1;
if (!isPlaying) {
webcamVideo.pause();
if (Math.abs(webcamVideo.currentTime - currentTime) > 0.05) {
@@ -983,7 +990,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
webcamVideo.play().catch(() => {
// Ignore webcam autoplay restoration failures.
});
}, [currentTime, isPlaying, webcamVideoPath]);
}, [currentTime, isPlaying, speedRegions, webcamVideoPath]);
useEffect(() => {
const webcamVideo = webcamVideoRef.current;