Skip to content

Build your personal knowledge base with Trilium Notes

client/media player: properly display the playing state when the active note changes

Adorian Doran5e4b931a1186
diff --git a/apps/client/src/widgets/type_widgets/file/Audio.tsx b/apps/client/src/widgets/type_widgets/file/Audio.tsx
index d1402fed01..9d8dd459b2 100644
--- a/apps/client/src/widgets/type_widgets/file/Audio.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Audio.tsx
@@ -24,7 +24,12 @@ export default function AudioPreview({ note, noteContext }: { note: FNote, noteC
}, []);
const onKeyDown = useKeyboardShortcuts(audioRef, togglePlayback);
- useEffect(() => setError(false), [note.noteId]);
+ useEffect(() => {
+ setError(false);
+ // The player instance is reused across notes (just a new src), which stops playback but doesn't
+ // reliably fire "pause" — reset so the controls don't keep showing the previous note's playing state.
+ setPlaying(false);
+ }, [note.noteId]);
const onError = useCallback(() => setError(true), []);
const siblingNavigation = useMediaSessionController(note, noteContext, "audio/", audioRef);
const { mode: playMode, setMode: setPlayMode } = useMediaPlayMode(noteContext, audioRef);
diff --git a/apps/client/src/widgets/type_widgets/file/Video.tsx b/apps/client/src/widgets/type_widgets/file/Video.tsx
index 2936057a01..9501af5dcb 100644
--- a/apps/client/src/widgets/type_widgets/file/Video.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Video.tsx
@@ -20,7 +20,12 @@ export default function VideoPreview({ note, noteContext }: { note: FNote, noteC
const [error, setError] = useState(false);
const { visible: controlsVisible, onMouseMove, flash: flashControls } = useAutoHideControls(videoRef, playing);
- useEffect(() => setError(false), [note.noteId]);
+ useEffect(() => {
+ setError(false);
+ // The player instance is reused across notes (just a new src), which stops playback but doesn't
+ // reliably fire "pause" — reset so the controls don't keep showing the previous note's playing state.
+ setPlaying(false);
+ }, [note.noteId]);
const onError = useCallback(() => setError(true), []);
const togglePlayback = useCallback(() => {