Skip to content

Build your personal knowledge base with Trilium Notes

feat(audio): reintroduce play button

Elian Dorana5a345728c40
diff --git a/apps/client/src/widgets/type_widgets/file/Audio.tsx b/apps/client/src/widgets/type_widgets/file/Audio.tsx
index 45b4693a97..45c2482215 100644
--- a/apps/client/src/widgets/type_widgets/file/Audio.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Audio.tsx
@@ -1,12 +1,27 @@
+import { useRef, useState } from "preact/hooks";
+
import FNote from "../../../entities/fnote";
import { getUrlForDownload } from "../../../services/open";
+import { PlayPauseButton } from "./MediaPlayer";
export default function AudioPreview({ note }: { note: FNote }) {
+ const [playing, setPlaying] = useState(false);
+ const audioRef = useRef<HTMLAudioElement>(null);
+
return (
- <audio
- class="audio-preview"
- src={getUrlForDownload(`api/notes/${note.noteId}/open-partial`)}
- controls
- />
+ <div className="audio-preview-wrapper">
+ <audio
+ class="audio-preview"
+ src={getUrlForDownload(`api/notes/${note.noteId}/open-partial`)}
+ ref={audioRef}
+ onPlay={() => setPlaying(true)}
+ onPause={() => setPlaying(false)}
+ />
+ <div className="video-preview-controls">
+ <div className="center">
+ <PlayPauseButton mediaRef={audioRef} playing={playing} />
+ </div>
+ </div>
+ </div>
);
}
\ No newline at end of file
diff --git a/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx b/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx
new file mode 100644
index 0000000000..54d76f16c6
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx
@@ -0,0 +1,26 @@
+import { RefObject } from "preact";
+
+import { t } from "../../../services/i18n";
+import ActionButton from "../../react/ActionButton";
+
+export function PlayPauseButton({ mediaRef, playing }: { mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement>, playing: boolean }) {
+ const togglePlayback = () => {
+ const media = mediaRef.current;
+ if (!media) return;
+
+ if (media.paused) {
+ media.play();
+ } else {
+ media.pause();
+ }
+ };
+
+ return (
+ <ActionButton
+ className="play-button"
+ icon={playing ? "bx bx-pause" : "bx bx-play"}
+ text={playing ? t("video.pause") : t("video.play")}
+ onClick={togglePlayback}
+ />
+ );
+}
\ No newline at end of file
diff --git a/apps/client/src/widgets/type_widgets/file/Video.tsx b/apps/client/src/widgets/type_widgets/file/Video.tsx
index 8197192e66..7c22649d3e 100644
--- a/apps/client/src/widgets/type_widgets/file/Video.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Video.tsx
@@ -10,6 +10,7 @@ import ActionButton from "../../react/ActionButton";
import Dropdown from "../../react/Dropdown";
import Icon from "../../react/Icon";
import NoItems from "../../react/NoItems";
+import { PlayPauseButton } from "./MediaPlayer";
function formatTime(seconds: number): string {
const mins = Math.floor(seconds / 60);
@@ -128,7 +129,7 @@ export default function VideoPreview({ note }: { note: FNote }) {
<div className="center">
<div className="spacer" />
<SkipButton videoRef={videoRef} seconds={-10} icon="bx bx-rewind" text={t("video.back-10s")} />
- <PlayPauseButton videoRef={videoRef} playing={playing} />
+ <PlayPauseButton mediaRef={videoRef} playing={playing} />
<SkipButton videoRef={videoRef} seconds={30} icon="bx bx-fast-forward" text={t("video.forward-30s")} />
<LoopButton videoRef={videoRef} />
</div>
@@ -174,28 +175,6 @@ function useAutoHideControls(videoRef: RefObject<HTMLVideoElement>, playing: boo
return { visible, onMouseMove, flash: onMouseMove };
}
-function PlayPauseButton({ videoRef, playing }: { videoRef: RefObject<HTMLVideoElement>, playing: boolean }) {
- const togglePlayback = () => {
- const video = videoRef.current;
- if (!video) return;
-
- if (video.paused) {
- video.play();
- } else {
- video.pause();
- }
- };
-
- return (
- <ActionButton
- className="play-button"
- icon={playing ? "bx bx-pause" : "bx bx-play"}
- text={playing ? t("video.pause") : t("video.play")}
- onClick={togglePlayback}
- />
- );
-}
-
function SkipButton({ videoRef, seconds, icon, text }: { videoRef: RefObject<HTMLVideoElement>, seconds: number, icon: string, text: string }) {
const skip = () => {
const video = videoRef.current;