Files
native-app/apps/expo/src/components/player/SeekButton.tsx
2024-03-07 13:12:14 +01:00

37 lines
981 B
TypeScript

import { MaterialIcons } from "@expo/vector-icons";
import { usePlayerStore } from "~/stores/player/store";
interface SeekProps {
type: "forward" | "backward";
}
export const SeekButton = ({ type }: SeekProps) => {
const videoRef = usePlayerStore((state) => state.videoRef);
const status = usePlayerStore((state) => state.status);
const setAudioPositionAsync = usePlayerStore(
(state) => state.setAudioPositionAsync,
);
return (
<MaterialIcons
name={type === "forward" ? "forward-10" : "replay-10"}
size={36}
color="white"
onPress={() => {
if (status?.isLoaded) {
const position =
type === "forward"
? status.positionMillis + 10000
: status.positionMillis - 10000;
videoRef?.setPositionAsync(position).catch(() => {
console.log("Error seeking backwards");
});
void setAudioPositionAsync(position);
}
}}
/>
);
};