diff --git a/src/components/playback/videoPlayer/buttons/SkipSegmentButton.tsx b/src/components/playback/videoPlayer/buttons/SkipSegmentButton.tsx index f059ccd..55be5b8 100644 --- a/src/components/playback/videoPlayer/buttons/SkipSegmentButton.tsx +++ b/src/components/playback/videoPlayer/buttons/SkipSegmentButton.tsx @@ -4,25 +4,32 @@ import { useShallow } from "zustand/shallow"; import { usePlaybackStore } from "@/utils/store/playback"; const SkipSegmentButton = () => { - const { mediaSegments, currentSegmentIndex, skipSegment, activeSegmentId } = - usePlaybackStore( - useShallow((state) => ({ - mediaSegments: state.metadata.mediaSegments, - currentSegmentIndex: state.nextSegmentIndex - 1, - skipSegment: state.skipSegment, - activeSegmentId: state.activeSegmentId, - })), - ); + const { + mediaSegments, + currentSegmentIndex, + skipSegment, + activeSegmentId, + isUserHovering, + isPlayerPlaying, + isUserSeeking, + } = usePlaybackStore( + useShallow((state) => ({ + mediaSegments: state.metadata.mediaSegments, + currentSegmentIndex: state.nextSegmentIndex - 1, + skipSegment: state.skipSegment, + activeSegmentId: state.activeSegmentId, + isUserHovering: state.playerState.isUserHovering, + isPlayerPlaying: state.playerState.isPlayerPlaying, + isUserSeeking: state.playerState.isUserSeeking, + })), + ); - console.info("Active segment ID:", activeSegmentId); - console.info("Current segment index:", currentSegmentIndex); - console.info("Media segments:", mediaSegments?.Items); if ( !mediaSegments?.Items?.length || currentSegmentIndex < 0 || !activeSegmentId ) { - return <>; // No segments to skip + return null; // No segments to skip } return ( @@ -33,8 +40,10 @@ const SkipSegmentButton = () => { color="white" style={{ position: "absolute", - bottom: "18vh", + bottom: + isUserHovering || !isPlayerPlaying || isUserSeeking ? "18vh" : "2em", right: "2em", + transition: "bottom 0.3s ease-in-out", zIndex: 10000, }} onClick={skipSegment} diff --git a/src/components/playback/videoPlayer/controls.tsx b/src/components/playback/videoPlayer/controls.tsx index 2383c47..8655458 100644 --- a/src/components/playback/videoPlayer/controls.tsx +++ b/src/components/playback/videoPlayer/controls.tsx @@ -38,13 +38,13 @@ import ProgressDislay from "./ProgressDisplay"; const VOLUME_SCROLL_INTERVAL = 0.02; type VideoPlayerControlsProps = { - isVisible: boolean; + // isVisible: boolean; onHover?: (event: MouseEvent) => void; onLeave?: (event: MouseEvent) => void; }; const VideoPlayerControls = ({ - isVisible, + // isVisible, onHover, onLeave, }: VideoPlayerControlsProps) => { @@ -69,6 +69,7 @@ const VideoPlayerControls = ({ increaseVolumeByStep, decreaseVolumeByStep, getCurrentTime, + isUserHovering, } = usePlaybackStore( useShallow((state) => ({ mediaSourceId: state.mediaSource.id, @@ -90,6 +91,7 @@ const VideoPlayerControls = ({ increaseVolumeByStep: state.increaseVolumeByStep, decreaseVolumeByStep: state.decreaseVolumeByStep, getCurrentTime: state.getCurrentTime, + isUserHovering: state.playerState.isUserHovering, })), ); @@ -168,7 +170,7 @@ const VideoPlayerControls = ({ return ( ({ itemId: state.metadata.item?.Id, @@ -132,6 +133,7 @@ export function VideoPlayer() { playbackStream: state.playbackStream, setIsBuffering: state.setIsBuffering, registerPlayerActions: state.registerPlayerActions, + setIsUserHovering: state.setIsUserHovering, })), ); @@ -372,7 +374,7 @@ export function VideoPlayer() { // } // }, [playerVolume]); - const [areControlsVisible, setAreControlsVisible] = useState(false); + const [_areControlsVisible, _setAreControlsVisiblee] = useState(false); const idleTimerRef = useRef(null); // Function to clear the existing idle timer @@ -388,7 +390,7 @@ export function VideoPlayer() { clearIdleTimer(); // Set a timer to hide the controls after 3 seconds of inactivity idleTimerRef.current = setTimeout(() => { - setAreControlsVisible(false); + setIsUserHovering(false); }, 3000); }, [clearIdleTimer]); @@ -396,14 +398,14 @@ export function VideoPlayer() { const handleMouseMove = useCallback(() => { // When the mouse moves, show the controls and restart the idle timer. - setAreControlsVisible(true); + setIsUserHovering(true); startIdleTimer(); }, [startIdleTimer]); const handleMouseLeave = useCallback(() => { // When the mouse leaves the player, clear the timer and hide the controls. clearIdleTimer(); - setAreControlsVisible(false); + setIsUserHovering(false); }, [clearIdleTimer]); const handleOnBuffer = useCallback(() => { @@ -438,7 +440,7 @@ export function VideoPlayer() { >