From 0baeb72abc804a3059f0cf1a3f20d580f9b47398 Mon Sep 17 00:00:00 2001 From: Pas <74743263+Pasithea0@users.noreply.github.com> Date: Sat, 10 May 2025 16:11:07 -0600 Subject: [PATCH] add details modal trailer volume bar --- src/components/overlays/DetailsModal.tsx | 105 ++++++++++++++++++++--- 1 file changed, 91 insertions(+), 14 deletions(-) diff --git a/src/components/overlays/DetailsModal.tsx b/src/components/overlays/DetailsModal.tsx index c6bb93a6..5f236e99 100644 --- a/src/components/overlays/DetailsModal.tsx +++ b/src/components/overlays/DetailsModal.tsx @@ -132,6 +132,8 @@ function DetailsContent({ const progress = useProgressStore((s) => s.items); const carouselRef = useRef(null); const activeEpisodeRef = useRef(null); + const [showVolumeBar, setShowVolumeBar] = useState(false); + const [volume, setVolume] = useState(0.5); const addBookmark = useBookmarkStore((s) => s.addBookmark); const removeBookmark = useBookmarkStore((s) => s.removeBookmark); @@ -179,11 +181,50 @@ function DetailsContent({ const toggleMute = () => { if (videoRef.current) { - videoRef.current.muted = !videoRef.current.muted; - setIsMuted(!isMuted); + const newMuted = !videoRef.current.muted; + videoRef.current.muted = newMuted; + setIsMuted(newMuted); + setShowVolumeBar(!newMuted); } }; + const handleVolumeChange = (e: React.ChangeEvent) => { + const newVolume = parseFloat(e.target.value); + setVolume(newVolume); + if (videoRef.current) { + videoRef.current.volume = newVolume; + if (newVolume === 0) { + videoRef.current.muted = true; + setIsMuted(true); + setShowVolumeBar(false); + } else { + videoRef.current.muted = false; + setIsMuted(false); + setShowVolumeBar(true); + } + } + }; + + // Hide volume bar after 2 seconds of inactivity + useEffect(() => { + if (!showVolumeBar || isMuted) return; + const timeout = setTimeout(() => setShowVolumeBar(false), 2000); + return () => clearTimeout(timeout); + }, [showVolumeBar, isMuted, volume]); + + // Hide volume bar when clicking outside + useEffect(() => { + if (!showVolumeBar) return; + const handleClick = (e: MouseEvent) => { + const bar = document.getElementById("vertical-volume-bar"); + if (bar && !bar.contains(e.target as Node)) { + setShowVolumeBar(false); + } + }; + document.addEventListener("mousedown", handleClick); + return () => document.removeEventListener("mousedown", handleClick); + }, [showVolumeBar]); + const togglePlay = () => { if (videoRef.current) { if (videoRef.current.paused) { @@ -317,6 +358,12 @@ function DetailsContent({ } }, [currentSeasonEpisodes, showProgress]); + useEffect(() => { + if (videoRef.current) { + videoRef.current.volume = 0.4; + } + }, []); + return (
{/* Backdrop - Even taller */} @@ -336,24 +383,54 @@ function DetailsContent({ className="absolute inset-0 w-full h-full object-cover cursor-pointer" autoPlay loop - muted + muted={isMuted} playsInline poster={data.backdrop} onClick={togglePlay} > - +
+ + {/* Volume Bar */} + {showVolumeBar && !isMuted && ( +
+ +
+ )} +
{isPaused && (