mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 10:33:26 +00:00
25 lines
549 B
TypeScript
25 lines
549 B
TypeScript
import { useCallback } from "react";
|
|
|
|
import { usePlayerStore } from "~/stores/player/store";
|
|
|
|
const speeds = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];
|
|
|
|
export const usePlaybackSpeed = () => {
|
|
const videoRef = usePlayerStore((state) => state.videoRef);
|
|
|
|
const changePlaybackSpeed = useCallback(
|
|
async (newValue: number) => {
|
|
if (videoRef) {
|
|
await videoRef.setRateAsync(newValue, true);
|
|
}
|
|
},
|
|
[videoRef],
|
|
);
|
|
|
|
return {
|
|
speeds,
|
|
currentSpeed: videoRef?.props.rate ?? 1,
|
|
changePlaybackSpeed,
|
|
} as const;
|
|
};
|