From 782159c7a965203f4f134dabe13634e59b579cc7 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Wed, 15 Nov 2023 01:41:32 -0800 Subject: feat: add support for srv3 --- src/app/components/VideoControls.tsx | 153 +++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 src/app/components/VideoControls.tsx (limited to 'src/app/components/VideoControls.tsx') diff --git a/src/app/components/VideoControls.tsx b/src/app/components/VideoControls.tsx new file mode 100644 index 0000000..bca8e97 --- /dev/null +++ b/src/app/components/VideoControls.tsx @@ -0,0 +1,153 @@ +import React, { useEffect, useState, useRef } from 'react'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { + faPlay, + faPause, + faExpand, + faCompress, + faVolumeUp, + faVolumeMute +} from '@fortawesome/free-solid-svg-icons'; + +// Define a TypeScript interface for the component's props +interface VideoControlsProps { + videoRef: React.RefObject; + isPlaying: boolean; + onPlayStateChange: (isPlaying: boolean) => void; + } +const VideoControls: React.FC = ({ videoRef, isPlaying, onPlayStateChange }) => { + const [isFullscreen, setIsFullscreen] = useState(false); + const [progress, setProgress] = useState(0); + const [volume, setVolume] = useState(1); + const [showVolumeSlider, setShowVolumeSlider] = useState(false); + const [currentTime, setCurrentTime] = useState(0); + + const formatTime = (seconds: number) => { + const hrs = Math.floor(seconds / 3600); + const mins = Math.floor((seconds % 3600) / 60); + const secs = Math.floor(seconds % 60); + if (hrs === 0) { + return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`; + } + return `${hrs.toString().padStart(2, '0')}:${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`; + }; + + useEffect(() => { + const updateProgress = () => { + const newProgress = (videoRef.current?.currentTime / videoRef.current?.duration) * 100; + setCurrentTime(videoRef.current?.currentTime || 0); + setProgress(newProgress || 0); + }; + + const currentVideoRef = videoRef.current; + currentVideoRef?.addEventListener('timeupdate', updateProgress); + return () => currentVideoRef?.removeEventListener('timeupdate', updateProgress); + }, [videoRef]); + + const handlePlayPause = () => { + if (videoRef.current?.paused) { + videoRef.current?.play(); + } else { + videoRef.current?.pause(); + } + onPlayStateChange(!videoRef.current?.paused); + }; + + const handleProgressChange = (e) => { + const newTime = (e.target.value / 100) * videoRef.current?.duration; + videoRef.current.currentTime = newTime; + setProgress(e.target.value); + }; + + const handleVolumeChange = (e) => { + const vol = e.target.value; + if (videoRef.current) { + videoRef.current.volume = vol; + } + setVolume(vol); + }; + + const toggleFullscreen = () => { + if (!document.fullscreenElement) { + videoRef.current?.requestFullscreen(); + setIsFullscreen(true); + } else { + document.exitFullscreen(); + setIsFullscreen(false); + } + }; + + const handleWheel = (e) => { + e.preventDefault(); + e.target.blur(); + }; + + return ( +
+ +
+ {formatTime(currentTime)} /{" "} + {formatTime(videoRef.current?.duration || 0)} +
+
+ +
+ + + + +
+ ); +}; + + +export default VideoControls; -- cgit v1.2.3