Skip to content

Commit

Permalink
feat(player): pause state on space key pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane committed Oct 31, 2023
1 parent 2e3c261 commit 03b3f7f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/components/PlayerAudio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { usePreviousNextVideos } from "../providers/PreviousNextTrack";
import { displayTimeBySeconds } from "../utils/displayTimeBySeconds";
import { showNotification } from "@mantine/notifications";
import { useTranslation } from "react-i18next";
import { useHotkeys } from "@mantine/hooks";

export const PlayerAudio = memo(() => {
const playerAudio = usePlayerAudio();
Expand All @@ -26,6 +27,23 @@ export const PlayerAudio = memo(() => {
const setPlayerMode = useSetPlayerMode();
const { t } = useTranslation();

const handlePressSpace = () => {
// @ts-ignore
const audio = playerAudio?.current?.audioEl.current as HTMLAudioElement;

if (playerState.paused) {
audio.play();
handlePlay();
} else {
audio.pause();
handlePause();
}
}

useHotkeys([
['space', handlePressSpace],
]);

const handlePause = () => {
setPlayerState((previousState) => ({
...previousState,
Expand Down

0 comments on commit 03b3f7f

Please sign in to comment.