import React from "react"; import { useTime } from "../context/time-context"; import { FaPlay, FaPause, FaBackward, FaForward, FaUndoAlt, FaArrowDown, FaArrowUp, } from "react-icons/fa"; const PlaybackBar: React.FC = () => { const { duration, isPlaying, setIsPlaying, currentTime, seek } = useTime(); const sliderActiveRef = React.useRef(false); const wasPlayingRef = React.useRef(false); const sliderValueRef = React.useRef(currentTime); const [sliderValue, setSliderValue] = React.useState(currentTime); // Only update sliderValue from context if not dragging React.useEffect(() => { if (!sliderActiveRef.current) { sliderValueRef.current = currentTime; setSliderValue(currentTime); } }, [currentTime]); const handleSliderChange = (e: React.ChangeEvent) => { const t = Number(e.target.value); sliderValueRef.current = t; setSliderValue(t); // Seek videos immediately while dragging (no debounce) seek(t); }; const handleSliderMouseDown = () => { sliderActiveRef.current = true; wasPlayingRef.current = isPlaying; setIsPlaying(false); }; const handleSliderMouseUp = () => { sliderActiveRef.current = false; // Final seek to exact slider position seek(sliderValueRef.current); if (wasPlayingRef.current) { setIsPlaying(true); } }; return (
{Math.floor(sliderValue)} / {Math.floor(duration)}

Space pause/unpause

prev/next episode

); }; export default PlaybackBar;