Skip to content

Build your personal knowledge base with Trilium Notes

client/media player: fix seek bar not working sometimes

Adorian Doran2c3b0905d417
diff --git a/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx b/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx
index cb54261f2c..8f1a940ab2 100644
--- a/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx
+++ b/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx
@@ -30,6 +30,13 @@ export function SeekBar({ mediaRef }: { mediaRef: RefObject<HTMLVideoElement | H
const onTimeUpdate = () => setCurrentTime(media.currentTime);
const onDurationChange = () => setDuration(media.duration);
+ // Seed from the element now: if its metadata already loaded before this (passive) effect ran — common
+ // for cached/fast media or a reused element — the initial durationchange/timeupdate already fired and
+ // the listeners below would miss them, leaving duration 0. That pins max=0, so the slider sticks at the
+ // start and any seek snaps playback back to 0.
+ onTimeUpdate();
+ onDurationChange();
+
media.addEventListener("timeupdate", onTimeUpdate);
media.addEventListener("durationchange", onDurationChange);
return () => {