feat: finish playback speed stuff

This commit is contained in:
Adrian Castro
2024-03-06 12:45:54 +01:00
parent ce38ece1ca
commit 6b5ee9aba0
3 changed files with 12 additions and 12 deletions

View File

@@ -55,7 +55,7 @@ export const PlaybackSpeedSelector = () => {
}} }}
> >
<Text>{speed}</Text> <Text>{speed}</Text>
{speed === currentSpeed.value && ( {speed === currentSpeed && (
<MaterialCommunityIcons <MaterialCommunityIcons
name="check-circle" name="check-circle"
size={24} size={24}

View File

@@ -228,13 +228,10 @@ export const VideoPlayer = () => {
const onReadyForDisplay = () => { const onReadyForDisplay = () => {
setIsLoading(false); setIsLoading(false);
setHasStartedPlaying(true); setHasStartedPlaying(true);
};
useEffect(() => {
if (videoRef) { if (videoRef) {
void videoRef.setRateAsync(currentSpeed.value, true); void videoRef.setRateAsync(currentSpeed, true);
} }
}, [currentSpeed.value, videoRef]); };
useEffect(() => { useEffect(() => {
const synchronizePlayback = async () => { const synchronizePlayback = async () => {
@@ -265,7 +262,7 @@ export const VideoPlayer = () => {
shouldPlay={shouldPlay} shouldPlay={shouldPlay}
resizeMode={resizeMode} resizeMode={resizeMode}
volume={currentVolume.value} volume={currentVolume.value}
rate={currentSpeed.value} rate={currentSpeed}
onLoadStart={onVideoLoadStart} onLoadStart={onVideoLoadStart}
onReadyForDisplay={onReadyForDisplay} onReadyForDisplay={onReadyForDisplay}
onPlaybackStatusUpdate={setStatus} onPlaybackStatusUpdate={setStatus}

View File

@@ -1,18 +1,21 @@
import { useCallback } from "react"; import { useCallback } from "react";
import { useSharedValue } from "react-native-reanimated";
import { usePlayerStore } from "~/stores/player/store";
export const usePlaybackSpeed = () => { export const usePlaybackSpeed = () => {
const speed = useSharedValue(1); const videoRef = usePlayerStore((state) => state.videoRef);
const changePlaybackSpeed = useCallback( const changePlaybackSpeed = useCallback(
(newValue: number) => { (newValue: number) => {
speed.value = newValue; if (videoRef) {
void videoRef.setRateAsync(newValue, true);
}
}, },
[speed], [videoRef],
); );
return { return {
currentSpeed: speed, currentSpeed: videoRef?.props.rate ?? 1,
changePlaybackSpeed, changePlaybackSpeed,
} as const; } as const;
}; };