Skip to content

Build your personal knowledge base with Trilium Notes

fix(video_player): loop can get out of sync with external control

Elian Doran2cb54d702173
diff --git a/apps/client/src/widgets/type_widgets/file/Video.tsx b/apps/client/src/widgets/type_widgets/file/Video.tsx
index 2ab4c76e50..ce45f059d6 100644
--- a/apps/client/src/widgets/type_widgets/file/Video.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Video.tsx
@@ -283,7 +283,17 @@ function PlaybackSpeed({ videoRef }: { videoRef: RefObject<HTMLVideoElement> })
}
function LoopButton({ videoRef }: { videoRef: RefObject<HTMLVideoElement> }) {
- const [loop, setLoop] = useState(false);
+ const [loop, setLoop] = useState(() => videoRef.current?.loop ?? false);
+
+ useEffect(() => {
+ const video = videoRef.current;
+ if (!video) return;
+ setLoop(video.loop);
+
+ const observer = new MutationObserver(() => setLoop(video.loop));
+ observer.observe(video, { attributes: true, attributeFilter: ["loop"] });
+ return () => observer.disconnect();
+ }, []);
const toggle = () => {
const video = videoRef.current;