From 59862ad901bf95122a7dab215dfe3c5583910464 Mon Sep 17 00:00:00 2001 From: Kyle Shanks Date: Tue, 21 Mar 2023 17:44:44 -0400 Subject: [PATCH] [C-2344] Update the web playbar scrubber to respect the playback speed of podcasts (#3075) --- packages/stems/src/components/Scrubber/Scrubber.tsx | 2 ++ packages/stems/src/components/Scrubber/Slider.tsx | 9 ++++++++- packages/stems/src/components/Scrubber/hooks.ts | 7 ++++--- packages/stems/src/components/Scrubber/types.ts | 5 +++++ .../web/src/components/play-bar/desktop/PlayBar.js | 11 +++++++++-- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/packages/stems/src/components/Scrubber/Scrubber.tsx b/packages/stems/src/components/Scrubber/Scrubber.tsx index da9ebd7a82c..6add6f07db7 100644 --- a/packages/stems/src/components/Scrubber/Scrubber.tsx +++ b/packages/stems/src/components/Scrubber/Scrubber.tsx @@ -34,6 +34,7 @@ export const Scrubber = ({ includeTimestamps, elapsedSeconds, totalSeconds, + playbackRate, onScrub, onScrubRelease, includeExpandedTargets, @@ -88,6 +89,7 @@ export const Scrubber = ({ isMobile={isMobile} elapsedSeconds={elapsedSeconds} totalSeconds={totalSeconds} + playbackRate={playbackRate} onScrub={onHandleScrub} onScrubRelease={onHandleScrubRelease} includeExpandedTargets={includeExpandedTargets} diff --git a/packages/stems/src/components/Scrubber/Slider.tsx b/packages/stems/src/components/Scrubber/Slider.tsx index 7de1e682d7f..db9abe7fd98 100644 --- a/packages/stems/src/components/Scrubber/Slider.tsx +++ b/packages/stems/src/components/Scrubber/Slider.tsx @@ -24,6 +24,7 @@ export const Slider = ({ isDisabled, elapsedSeconds, totalSeconds, + playbackRate, onScrub, onScrubRelease, includeExpandedTargets = true, @@ -54,7 +55,8 @@ export const Slider = ({ trackRef, handleRef, elapsedSeconds, - totalSeconds + totalSeconds, + playbackRate ) /** @@ -219,6 +221,11 @@ export const Slider = ({ } }, [isPlaying, dragPercent, play, pause]) + useEffect(() => { + setPercent(elapsedSeconds / totalSeconds) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [playbackRate]) + // When the key changes, reset the animation useEffect(() => { if (mediaKey !== previousMediaKey) { diff --git a/packages/stems/src/components/Scrubber/hooks.ts b/packages/stems/src/components/Scrubber/hooks.ts index 8fd79a92a90..9d103331289 100644 --- a/packages/stems/src/components/Scrubber/hooks.ts +++ b/packages/stems/src/components/Scrubber/hooks.ts @@ -27,18 +27,19 @@ export const useAnimations = ( trackRef: React.MutableRefObject, handleRef: React.MutableRefObject, elapsedSeconds: number, - totalSeconds: number + totalSeconds: number, + playbackRate = 1 ) => { /** Animates from the current position to the end over the remaining seconds. */ const play = useCallback(() => { - const timeRemaining = totalSeconds - elapsedSeconds + const timeRemaining = (totalSeconds - elapsedSeconds) / playbackRate animate( trackRef, handleRef, `transform ${timeRemaining}s linear`, 'translate(100%)' ) - }, [trackRef, handleRef, elapsedSeconds, totalSeconds]) + }, [totalSeconds, elapsedSeconds, playbackRate, trackRef, handleRef]) /** * Pauses the animation at the current position. diff --git a/packages/stems/src/components/Scrubber/types.ts b/packages/stems/src/components/Scrubber/types.ts index b47d90f88d4..8ad423e75ad 100644 --- a/packages/stems/src/components/Scrubber/types.ts +++ b/packages/stems/src/components/Scrubber/types.ts @@ -41,6 +41,11 @@ export type ScrubberProps = { */ totalSeconds: number + /** + * The speed that the media is being played at + */ + playbackRate: number + /** * Fired incrementally as the user drags the scrubber. */ diff --git a/packages/web/src/components/play-bar/desktop/PlayBar.js b/packages/web/src/components/play-bar/desktop/PlayBar.js index 176a961446a..6b95eb9ede8 100644 --- a/packages/web/src/components/play-bar/desktop/PlayBar.js +++ b/packages/web/src/components/play-bar/desktop/PlayBar.js @@ -15,7 +15,8 @@ import { playerActions, playerSelectors, queueSelectors, - FeatureFlags + FeatureFlags, + playbackRateValueMap } from '@audius/common' import { Scrubber } from '@audius/stems' import { push as pushRoute } from 'connected-react-router' @@ -48,7 +49,8 @@ const { getPlaying, getCounter, getUid: getPlayingUid, - getBuffering + getBuffering, + getPlaybackRate } = playerSelectors const { seek, reset } = playerActions @@ -296,6 +298,7 @@ class PlayBar extends Component { collectible, isPlaying, isBuffering, + playbackRate, userId, theme } = this.props @@ -393,6 +396,9 @@ class PlayBar extends Component { isPlaying={isPlaying && !isBuffering} isDisabled={!uid && !collectible} includeTimestamps + playbackRate={ + isLongFormContent ? playbackRateValueMap[playbackRate] : 1 + } elapsedSeconds={audioPlayer?.getPosition()} totalSeconds={duration} style={{ @@ -505,6 +511,7 @@ const makeMapStateToProps = () => { isPlaying: getPlaying(state), isBuffering: getBuffering(state), playingUid: getPlayingUid(state), + playbackRate: getPlaybackRate(state), lineupHasTracks: getLineupHasTracks( getLineupSelectorForRoute(state), state