Skip to content

Commit

Permalink
Added extra speed steps. (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTV12345 authored Nov 6, 2023
1 parent e434e5b commit b6d7f1b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions ui/src/components/PlayerTimeControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ type PlayerTimeControlsProps = {
refItem: RefObject<HTMLAudioElement>
}


const SPEED_STEPS = [0.5, 1,1.1,1.25, 1.5, 2, 2.5, 3]


export const PlayerTimeControls: FC<PlayerTimeControlsProps> = ({ refItem }) => {
const setSelectedEpisodes = useCommon(state => state.setSelectedEpisodes)
const currentPodcastEpisode = useAudioPlayer(state => state.currentPodcastEpisode)
Expand Down Expand Up @@ -111,14 +115,16 @@ export const PlayerTimeControls: FC<PlayerTimeControlsProps> = ({ 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 (
Expand Down

0 comments on commit b6d7f1b

Please sign in to comment.