From 9f7432450b85f4e97e698be4b436e4c99c6cea98 Mon Sep 17 00:00:00 2001 From: qtchaos <72168435+qtchaos@users.noreply.github.com> Date: Thu, 28 Dec 2023 21:43:52 +0200 Subject: [PATCH 1/4] Improve video progress/playback keybinds --- .../player/internals/KeyboardEvents.tsx | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/components/player/internals/KeyboardEvents.tsx b/src/components/player/internals/KeyboardEvents.tsx index 4e8e3f81..5900a990 100644 --- a/src/components/player/internals/KeyboardEvents.tsx +++ b/src/components/player/internals/KeyboardEvents.tsx @@ -9,6 +9,8 @@ import { useEmpheralVolumeStore } from "@/stores/volume"; export function KeyboardEvents() { const router = useOverlayRouter(""); const display = usePlayerStore((s) => s.display); + const mediaProgress = usePlayerStore((s) => s.progress); + const { isSeeking } = usePlayerStore((s) => s.interface); const mediaPlaying = usePlayerStore((s) => s.mediaPlaying); const time = usePlayerStore((s) => s.progress.time); const { setVolume, toggleMute } = useVolume(); @@ -27,6 +29,8 @@ export function KeyboardEvents() { toggleLastUsed, display, mediaPlaying, + mediaProgress, + isSeeking, isRolling, time, router, @@ -40,6 +44,8 @@ export function KeyboardEvents() { toggleLastUsed, display, mediaPlaying, + mediaProgress, + isSeeking, isRolling, time, router, @@ -52,6 +58,8 @@ export function KeyboardEvents() { toggleLastUsed, display, mediaPlaying, + mediaProgress, + isSeeking, isRolling, time, router, @@ -83,11 +91,38 @@ export function KeyboardEvents() { ); if (k === "m") dataRef.current.toggleMute(); + // Video playback speed + if (k === ">" || k === "<") { + const playbackRates = [0.25, 0.5, 1, 1.5, 2]; + const idx = playbackRates.indexOf( + dataRef.current.mediaPlaying?.playbackRate, + ); + const nextIdx = idx + (k === ">" ? 1 : -1); + const next = playbackRates[nextIdx]; + if (next) dataRef.current.display?.setPlaybackRate(next); + } + // Video progress if (k === "ArrowRight") dataRef.current.display?.setTime(dataRef.current.time + 5); if (k === "ArrowLeft") dataRef.current.display?.setTime(dataRef.current.time - 5); + if (k === "j") + dataRef.current.display?.setTime(dataRef.current.time - 10); + if (k === "l") + dataRef.current.display?.setTime(dataRef.current.time + 10); + if (k === "." && dataRef.current.mediaPlaying?.isPaused) + dataRef.current.display?.setTime(dataRef.current.time + 1); + if (k === "," && dataRef.current.mediaPlaying?.isPaused) + dataRef.current.display?.setTime(dataRef.current.time - 1); + if (/\d/.exec(k) && !dataRef.current.isSeeking) { + const num = parseInt(k, 10); + if (num === 0) dataRef.current.display?.setTime(0); + const percent = num / 10; + dataRef.current.display?.setTime( + dataRef.current.mediaProgress.duration * percent, + ); + } // Utils if (k === "f") dataRef.current.display?.toggleFullscreen(); From c3494c2f845682435e5b7f32679c0e4090017206 Mon Sep 17 00:00:00 2001 From: qtchaos <72168435+qtchaos@users.noreply.github.com> Date: Thu, 28 Dec 2023 21:57:14 +0200 Subject: [PATCH 2/4] Refactor video playback speed options --- src/components/player/internals/KeyboardEvents.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/player/internals/KeyboardEvents.tsx b/src/components/player/internals/KeyboardEvents.tsx index 5900a990..29432a4f 100644 --- a/src/components/player/internals/KeyboardEvents.tsx +++ b/src/components/player/internals/KeyboardEvents.tsx @@ -93,12 +93,10 @@ export function KeyboardEvents() { // Video playback speed if (k === ">" || k === "<") { - const playbackRates = [0.25, 0.5, 1, 1.5, 2]; - const idx = playbackRates.indexOf( - dataRef.current.mediaPlaying?.playbackRate, - ); + const options = [0.25, 0.5, 1, 1.5, 2]; + const idx = options.indexOf(dataRef.current.mediaPlaying?.playbackRate); const nextIdx = idx + (k === ">" ? 1 : -1); - const next = playbackRates[nextIdx]; + const next = options[nextIdx]; if (next) dataRef.current.display?.setPlaybackRate(next); } From 27b28a6d96b4742182f4cb96841e6b52c1110712 Mon Sep 17 00:00:00 2001 From: qtchaos <72168435+qtchaos@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:18:47 +0200 Subject: [PATCH 3/4] Remove seeking with numbers. --- src/components/player/internals/KeyboardEvents.tsx | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/components/player/internals/KeyboardEvents.tsx b/src/components/player/internals/KeyboardEvents.tsx index 29432a4f..6373b0b5 100644 --- a/src/components/player/internals/KeyboardEvents.tsx +++ b/src/components/player/internals/KeyboardEvents.tsx @@ -113,14 +113,6 @@ export function KeyboardEvents() { dataRef.current.display?.setTime(dataRef.current.time + 1); if (k === "," && dataRef.current.mediaPlaying?.isPaused) dataRef.current.display?.setTime(dataRef.current.time - 1); - if (/\d/.exec(k) && !dataRef.current.isSeeking) { - const num = parseInt(k, 10); - if (num === 0) dataRef.current.display?.setTime(0); - const percent = num / 10; - dataRef.current.display?.setTime( - dataRef.current.mediaProgress.duration * percent, - ); - } // Utils if (k === "f") dataRef.current.display?.toggleFullscreen(); From 5e52ea8e8fdcea482be57b75ee94c46c00c5e33d Mon Sep 17 00:00:00 2001 From: qtchaos <72168435+qtchaos@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:53:47 +0200 Subject: [PATCH 4/4] Add check for non existent index. --- src/components/player/internals/KeyboardEvents.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/player/internals/KeyboardEvents.tsx b/src/components/player/internals/KeyboardEvents.tsx index 6373b0b5..3a833e76 100644 --- a/src/components/player/internals/KeyboardEvents.tsx +++ b/src/components/player/internals/KeyboardEvents.tsx @@ -94,7 +94,8 @@ export function KeyboardEvents() { // Video playback speed if (k === ">" || k === "<") { const options = [0.25, 0.5, 1, 1.5, 2]; - const idx = options.indexOf(dataRef.current.mediaPlaying?.playbackRate); + let idx = options.indexOf(dataRef.current.mediaPlaying?.playbackRate); + if (idx === -1) idx = options.indexOf(1); const nextIdx = idx + (k === ">" ? 1 : -1); const next = options[nextIdx]; if (next) dataRef.current.display?.setPlaybackRate(next);