mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 16:33:26 +00:00
feat: finish playback speed stuff
This commit is contained in:
@@ -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}
|
||||||
|
@@ -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}
|
||||||
|
@@ -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;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user