Skip to content

Build your personal knowledge base with Trilium Notes

client/media player: add audio navigation support

Adorian Doran934cfce2c672
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index c86550f4e1..bea7869d69 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1178,6 +1178,8 @@
"forward-30s": "Forward 30s",
"previous-video": "Previous video: {{- title}}",
"next-video": "Next video: {{- title}}",
+ "previous-audio": "Previous audio: {{- title}}",
+ "next-audio": "Next audio: {{- title}}",
"mute": "Mute (M)",
"unmute": "Unmute (M)",
"playback-speed": "Playback speed",
diff --git a/apps/client/src/widgets/type_widgets/File.tsx b/apps/client/src/widgets/type_widgets/File.tsx
index e33c77b7eb..8f8fca1f7b 100644
--- a/apps/client/src/widgets/type_widgets/File.tsx
+++ b/apps/client/src/widgets/type_widgets/File.tsx
@@ -20,7 +20,7 @@ export default function FileTypeWidget({ note, parentComponent, noteContext }: T
} else if (note.mime.startsWith("video/")) {
return <VideoPreview note={note} noteContext={noteContext} />;
} else if (note.mime.startsWith("audio/")) {
- return <AudioPreview note={note} />;
+ return <AudioPreview note={note} noteContext={noteContext} />;
}
return <NoPreview />;
diff --git a/apps/client/src/widgets/type_widgets/file/Audio.tsx b/apps/client/src/widgets/type_widgets/file/Audio.tsx
index 051c5c15e1..21715fb087 100644
--- a/apps/client/src/widgets/type_widgets/file/Audio.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Audio.tsx
@@ -1,13 +1,14 @@
import { MutableRef, useCallback, useEffect, useRef, useState } from "preact/hooks";
+import type NoteContext from "../../../components/note_context";
import FNote from "../../../entities/fnote";
import { t } from "../../../services/i18n";
import { getUrlForDownload } from "../../../services/open";
import Icon from "../../react/Icon";
import NoItems from "../../react/NoItems";
-import { LoopButton, PlaybackSpeed, PlayPauseButton, SeekBar, SkipButton, VolumeControl } from "./MediaPlayer";
+import { LoopButton, MediaSiblingButton, PlaybackSpeed, PlayPauseButton, SeekBar, SkipButton, useMediaSiblingNavigation, VolumeControl } from "./MediaPlayer";
-export default function AudioPreview({ note }: { note: FNote }) {
+export default function AudioPreview({ note, noteContext }: { note: FNote, noteContext?: NoteContext }) {
const wrapperRef = useRef<HTMLDivElement>(null);
const audioRef = useRef<HTMLAudioElement>(null);
const [playing, setPlaying] = useState(false);
@@ -25,6 +26,7 @@ export default function AudioPreview({ note }: { note: FNote }) {
useEffect(() => setError(false), [note.noteId]);
const onError = useCallback(() => setError(true), []);
+ const siblingNavigation = useMediaSiblingNavigation(note, noteContext, "audio/");
if (error) {
return <NoItems icon="bx bx-volume-mute" text={t("media.unsupported-format", { mime: note.mime.replace("/", "-") })} />;
@@ -53,9 +55,11 @@ export default function AudioPreview({ note }: { note: FNote }) {
<div className="center">
<div className="spacer" />
+ <MediaSiblingButton navigation={siblingNavigation} direction="previous" tooltipI18nKey="media.previous-audio" />
<SkipButton mediaRef={audioRef} seconds={-10} icon="bx bx-rewind" text={t("media.back-10s")} />
<PlayPauseButton playing={playing} togglePlayback={togglePlayback} />
<SkipButton mediaRef={audioRef} seconds={30} icon="bx bx-fast-forward" text={t("media.forward-30s")} />
+ <MediaSiblingButton navigation={siblingNavigation} direction="next" tooltipI18nKey="media.next-audio" />
<LoopButton mediaRef={audioRef} />
</div>