import { useEffect, useState, useRef } from "react"; import { formatTime } from "@/lib/timeUtils"; import '../styles/IOSVideoPlayer.css'; interface IOSVideoPlayerProps { videoRef: React.RefObject; currentTime: number; duration: number; } const IOSVideoPlayer = ({ videoRef, currentTime, duration, }: IOSVideoPlayerProps) => { const [videoUrl, setVideoUrl] = useState(""); const [iosVideoRef, setIosVideoRef] = useState(null); // Refs for hold-to-continue functionality const incrementIntervalRef = useRef(null); const decrementIntervalRef = useRef(null); // Clean up intervals on unmount useEffect(() => { return () => { if (incrementIntervalRef.current) clearInterval(incrementIntervalRef.current); if (decrementIntervalRef.current) clearInterval(decrementIntervalRef.current); }; }, []); // Get the video source URL from the main player useEffect(() => { if (videoRef.current && videoRef.current.querySelector('source')) { const source = videoRef.current.querySelector('source') as HTMLSourceElement; if (source && source.src) { setVideoUrl(source.src); } } else { // Fallback to sample video if needed setVideoUrl("/videos/sample-video-37s.mp4"); } }, [videoRef]); // Function to jump 15 seconds backward const jumpBackward15 = () => { if (iosVideoRef) { const newTime = Math.max(0, iosVideoRef.currentTime - 15); iosVideoRef.currentTime = newTime; } }; // Function to jump 15 seconds forward const jumpForward15 = () => { if (iosVideoRef) { const newTime = Math.min(iosVideoRef.duration, iosVideoRef.currentTime + 15); iosVideoRef.currentTime = newTime; } }; // Start continuous 50ms increment when button is held const startIncrement = (e: React.MouseEvent | React.TouchEvent) => { // Prevent default to avoid text selection e.preventDefault(); if (!iosVideoRef) return; if (incrementIntervalRef.current) clearInterval(incrementIntervalRef.current); // First immediate adjustment iosVideoRef.currentTime = Math.min(iosVideoRef.duration, iosVideoRef.currentTime + 0.05); // Setup continuous adjustment incrementIntervalRef.current = setInterval(() => { if (iosVideoRef) { iosVideoRef.currentTime = Math.min(iosVideoRef.duration, iosVideoRef.currentTime + 0.05); } }, 100); }; // Stop continuous increment const stopIncrement = () => { if (incrementIntervalRef.current) { clearInterval(incrementIntervalRef.current); incrementIntervalRef.current = null; } }; // Start continuous 50ms decrement when button is held const startDecrement = (e: React.MouseEvent | React.TouchEvent) => { // Prevent default to avoid text selection e.preventDefault(); if (!iosVideoRef) return; if (decrementIntervalRef.current) clearInterval(decrementIntervalRef.current); // First immediate adjustment iosVideoRef.currentTime = Math.max(0, iosVideoRef.currentTime - 0.05); // Setup continuous adjustment decrementIntervalRef.current = setInterval(() => { if (iosVideoRef) { iosVideoRef.currentTime = Math.max(0, iosVideoRef.currentTime - 0.05); } }, 100); }; // Stop continuous decrement const stopDecrement = () => { if (decrementIntervalRef.current) { clearInterval(decrementIntervalRef.current); decrementIntervalRef.current = null; } }; return (
{/* Current Time / Duration Display */}
{formatTime(currentTime)} / {formatTime(duration)}
{/* iOS-optimized Video Element with Native Controls */} {/* iOS Video Skip Controls */}
{/* iOS Fine Control Buttons */}

This player uses native iOS controls for better compatibility with iOS devices.

); }; export default IOSVideoPlayer;