Merge pull request #612 from qtchaos/keyboard-improvements

Improve video progress/playback keybinds
This commit is contained in:
William Oldham 2023-12-29 12:22:36 +00:00 committed by GitHub
commit b0fa2a6b0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,6 +9,8 @@ import { useEmpheralVolumeStore } from "@/stores/volume";
export function KeyboardEvents() { export function KeyboardEvents() {
const router = useOverlayRouter(""); const router = useOverlayRouter("");
const display = usePlayerStore((s) => s.display); 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 mediaPlaying = usePlayerStore((s) => s.mediaPlaying);
const time = usePlayerStore((s) => s.progress.time); const time = usePlayerStore((s) => s.progress.time);
const { setVolume, toggleMute } = useVolume(); const { setVolume, toggleMute } = useVolume();
@ -27,6 +29,8 @@ export function KeyboardEvents() {
toggleLastUsed, toggleLastUsed,
display, display,
mediaPlaying, mediaPlaying,
mediaProgress,
isSeeking,
isRolling, isRolling,
time, time,
router, router,
@ -40,6 +44,8 @@ export function KeyboardEvents() {
toggleLastUsed, toggleLastUsed,
display, display,
mediaPlaying, mediaPlaying,
mediaProgress,
isSeeking,
isRolling, isRolling,
time, time,
router, router,
@ -52,6 +58,8 @@ export function KeyboardEvents() {
toggleLastUsed, toggleLastUsed,
display, display,
mediaPlaying, mediaPlaying,
mediaProgress,
isSeeking,
isRolling, isRolling,
time, time,
router, router,
@ -83,11 +91,29 @@ export function KeyboardEvents() {
); );
if (k === "m") dataRef.current.toggleMute(); if (k === "m") dataRef.current.toggleMute();
// Video playback speed
if (k === ">" || k === "<") {
const options = [0.25, 0.5, 1, 1.5, 2];
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);
}
// Video progress // Video progress
if (k === "ArrowRight") if (k === "ArrowRight")
dataRef.current.display?.setTime(dataRef.current.time + 5); dataRef.current.display?.setTime(dataRef.current.time + 5);
if (k === "ArrowLeft") if (k === "ArrowLeft")
dataRef.current.display?.setTime(dataRef.current.time - 5); 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);
// Utils // Utils
if (k === "f") dataRef.current.display?.toggleFullscreen(); if (k === "f") dataRef.current.display?.toggleFullscreen();