diff --git a/apps/expo/src/components/player/BottomControls.tsx b/apps/expo/src/components/player/BottomControls.tsx index b6ced21..028eb25 100644 --- a/apps/expo/src/components/player/BottomControls.tsx +++ b/apps/expo/src/components/player/BottomControls.tsx @@ -3,6 +3,7 @@ import { View } from "react-native"; import { usePlayerStore } from "~/stores/player/store"; import { Text } from "../ui/Text"; import { Controls } from "./Controls"; +import { ProgressBar } from "./ProgressBar"; import { mapMillisecondsToTime } from "./utils"; export const BottomControls = () => { @@ -13,10 +14,11 @@ export const BottomControls = () => { return ( - + {mapMillisecondsToTime(status.positionMillis ?? 0)} + {mapMillisecondsToTime(status.durationMillis ?? 0)} diff --git a/apps/expo/src/components/player/ProgressBar.tsx b/apps/expo/src/components/player/ProgressBar.tsx new file mode 100644 index 0000000..a2b6a3f --- /dev/null +++ b/apps/expo/src/components/player/ProgressBar.tsx @@ -0,0 +1,80 @@ +import { useCallback, useRef } from "react"; +import { Dimensions, PanResponder, TouchableOpacity, View } from "react-native"; + +import { usePlayerStore } from "~/stores/player/store"; + +export const ProgressBar = () => { + const status = usePlayerStore((state) => state.status); + const videoRef = usePlayerStore((state) => state.videoRef); + + const screenWidth = Dimensions.get("window").width; + const progressBarWidth = screenWidth - 40; // Adjust the padding as needed + + const updateProgress = useCallback( + (newProgress: number) => { + videoRef?.setStatusAsync({ positionMillis: newProgress }).catch(() => { + console.log("Error updating progress"); + }); + }, + [videoRef], + ); + + const panResponder = useRef( + PanResponder.create({ + onStartShouldSetPanResponder: () => true, + onMoveShouldSetPanResponder: () => true, + onPanResponderMove: (e, gestureState) => { + console.log(gestureState.moveX, gestureState.x0, gestureState.dx); + }, + onPanResponderRelease: (e, gestureState) => { + console.log("onPanResponderRelease"); + const { moveX, x0 } = gestureState; + const newProgress = (moveX - x0) / progressBarWidth; + updateProgress(newProgress); + }, + }), + ).current; + + if (status?.isLoaded) { + const progressRatio = + status.durationMillis && status.durationMillis !== 0 + ? status.positionMillis / status.durationMillis + : 0; + return ( + + {/* Progress Dot */} + + + + + {/* Full bar */} + + {/* TODO: Preloaded */} + + + {/* Progress */} + + + + ); + } +};