From b6d7f1b665670a64dd5f139563d3939c56d9e5bb Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+SamTV12345@users.noreply.github.com> Date: Mon, 6 Nov 2023 16:15:06 +0100 Subject: [PATCH] Added extra speed steps. (#394) --- ui/src/components/PlayerTimeControls.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ui/src/components/PlayerTimeControls.tsx b/ui/src/components/PlayerTimeControls.tsx index 3857f993..fbbf98e0 100644 --- a/ui/src/components/PlayerTimeControls.tsx +++ b/ui/src/components/PlayerTimeControls.tsx @@ -17,6 +17,10 @@ type PlayerTimeControlsProps = { refItem: RefObject } + +const SPEED_STEPS = [0.5, 1,1.1,1.25, 1.5, 2, 2.5, 3] + + export const PlayerTimeControls: FC = ({ refItem }) => { const setSelectedEpisodes = useCommon(state => state.setSelectedEpisodes) const currentPodcastEpisode = useAudioPlayer(state => state.currentPodcastEpisode) @@ -111,14 +115,16 @@ export const PlayerTimeControls: FC = ({ refItem }) => const changeSpeed = () => { if (refItem.current === null) return - let newSpeed = speed + 0.5 + const currentIndex = SPEED_STEPS.indexOf(speed) - if (newSpeed > 3) { - newSpeed = 1 + if (currentIndex === SPEED_STEPS.length - 1) { + refItem.current.playbackRate = SPEED_STEPS[0] + setPlaybackRate(SPEED_STEPS[0]) + return } - refItem.current.playbackRate = newSpeed - setPlaybackRate(newSpeed) + refItem.current.playbackRate = SPEED_STEPS[currentIndex + 1] + setPlaybackRate(SPEED_STEPS[currentIndex + 1]) } return (