Skip to content

Build your personal knowledge base with Trilium Notes

feat(audio): introduce skip buttons

Elian Doran6b974c2ac7bf
diff --git a/apps/client/src/widgets/type_widgets/file/Audio.tsx b/apps/client/src/widgets/type_widgets/file/Audio.tsx
index 99de10caf2..ffd83b5e51 100644
--- a/apps/client/src/widgets/type_widgets/file/Audio.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Audio.tsx
@@ -1,8 +1,9 @@
import { useRef, useState } from "preact/hooks";
import FNote from "../../../entities/fnote";
+import { t } from "../../../services/i18n";
import { getUrlForDownload } from "../../../services/open";
-import { PlayPauseButton, SeekBar, VolumeControl } from "./MediaPlayer";
+import { PlayPauseButton, SeekBar, SkipButton, VolumeControl } from "./MediaPlayer";
export default function AudioPreview({ note }: { note: FNote }) {
const [playing, setPlaying] = useState(false);
@@ -24,7 +25,9 @@ export default function AudioPreview({ note }: { note: FNote }) {
<div className="left" />
<div className="center">
+ <SkipButton mediaRef={audioRef} seconds={-10} icon="bx bx-rewind" text={t("video.back-10s")} />
<PlayPauseButton mediaRef={audioRef} playing={playing} />
+ <SkipButton mediaRef={audioRef} seconds={30} icon="bx bx-fast-forward" text={t("video.forward-30s")} />
</div>
<div className="right">
diff --git a/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx b/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx
index 376984ca5c..6049a53ee6 100644
--- a/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx
+++ b/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx
@@ -134,3 +134,15 @@ export function VolumeControl({ mediaRef }: { mediaRef: RefObject<HTMLVideoEleme
</div>
);
}
+
+export function SkipButton({ mediaRef, seconds, icon, text }: { mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement>, seconds: number, icon: string, text: string }) {
+ const skip = () => {
+ const media = mediaRef.current;
+ if (!media) return;
+ media.currentTime = Math.max(0, Math.min(media.duration, media.currentTime + seconds));
+ };
+
+ return (
+ <ActionButton icon={icon} text={text} onClick={skip} />
+ );
+}
diff --git a/apps/client/src/widgets/type_widgets/file/Video.tsx b/apps/client/src/widgets/type_widgets/file/Video.tsx
index f6a22e3d4c..c22725f70e 100644
--- a/apps/client/src/widgets/type_widgets/file/Video.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Video.tsx
@@ -10,7 +10,7 @@ import ActionButton from "../../react/ActionButton";
import Dropdown from "../../react/Dropdown";
import Icon from "../../react/Icon";
import NoItems from "../../react/NoItems";
-import { PlayPauseButton, SeekBar, VolumeControl } from "./MediaPlayer";
+import { PlayPauseButton, SeekBar, SkipButton, VolumeControl } from "./MediaPlayer";
const AUTO_HIDE_DELAY = 3000;
@@ -122,9 +122,9 @@ export default function VideoPreview({ note }: { note: FNote }) {
</div>
<div className="center">
<div className="spacer" />
- <SkipButton videoRef={videoRef} seconds={-10} icon="bx bx-rewind" text={t("video.back-10s")} />
+ <SkipButton mediaRef={videoRef} seconds={-10} icon="bx bx-rewind" text={t("video.back-10s")} />
<PlayPauseButton mediaRef={videoRef} playing={playing} />
- <SkipButton videoRef={videoRef} seconds={30} icon="bx bx-fast-forward" text={t("video.forward-30s")} />
+ <SkipButton mediaRef={videoRef} seconds={30} icon="bx bx-fast-forward" text={t("video.forward-30s")} />
<LoopButton videoRef={videoRef} />
</div>
<div className="right">
@@ -169,18 +169,6 @@ function useAutoHideControls(videoRef: RefObject<HTMLVideoElement>, playing: boo
return { visible, onMouseMove, flash: onMouseMove };
}
-function SkipButton({ videoRef, seconds, icon, text }: { videoRef: RefObject<HTMLVideoElement>, seconds: number, icon: string, text: string }) {
- const skip = () => {
- const video = videoRef.current;
- if (!video) return;
- video.currentTime = Math.max(0, Math.min(video.duration, video.currentTime + seconds));
- };
-
- return (
- <ActionButton icon={icon} text={text} onClick={skip} />
- );
-}
-
const PLAYBACK_SPEEDS = [0.5, 1, 1.25, 1.5, 2];
function PlaybackSpeed({ videoRef }: { videoRef: RefObject<HTMLVideoElement> }) {