feat: change skip segment button position depending if controls are visible
This commit is contained in:
3 files changed
+36
-23
No files matched your search
@@ -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}
|
||||
|
||||
@@ -38,13 +38,13 @@ import ProgressDislay from "./ProgressDisplay";
|
||||
const VOLUME_SCROLL_INTERVAL = 0.02;
|
||||
|
||||
type VideoPlayerControlsProps = {
|
||||
isVisible: boolean;
|
||||
// isVisible: boolean;
|
||||
onHover?: (event: MouseEvent<HTMLDivElement>) => void;
|
||||
onLeave?: (event: MouseEvent<HTMLDivElement>) => 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 (
|
||||
<motion.div
|
||||
className={
|
||||
isVisible || isUserSeeking || !isPlayerPlaying
|
||||
isUserHovering || isUserSeeking || !isPlayerPlaying
|
||||
? "video-player-osd hovering"
|
||||
: "video-player-osd"
|
||||
}
|
||||
@@ -179,7 +181,7 @@ const VideoPlayerControls = ({
|
||||
opacity: 0,
|
||||
}}
|
||||
animate={{
|
||||
opacity: isVisible || isUserSeeking || !isPlayerPlaying ? 1 : 0,
|
||||
opacity: isUserHovering || isUserSeeking || !isPlayerPlaying ? 1 : 0,
|
||||
}}
|
||||
style={{
|
||||
zIndex: 2,
|
||||
|
||||
@@ -107,6 +107,7 @@ export function VideoPlayer() {
|
||||
setIsBuffering,
|
||||
registerPlayerActions,
|
||||
toggleIsPlayerFullscreen,
|
||||
setIsUserHovering,
|
||||
} = usePlaybackStore(
|
||||
useShallow((state) => ({
|
||||
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<NodeJS.Timeout | null>(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() {
|
||||
>
|
||||
<LoadingIndicator />
|
||||
<VideoPlayerControls
|
||||
isVisible={areControlsVisible}
|
||||
// isVisible={areControlsVisible}
|
||||
onHover={handleMouseMove}
|
||||
onLeave={handleMouseLeave}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user