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";
|
import { usePlaybackStore } from "@/utils/store/playback";
|
||||||
|
|
||||||
const SkipSegmentButton = () => {
|
const SkipSegmentButton = () => {
|
||||||
const { mediaSegments, currentSegmentIndex, skipSegment, activeSegmentId } =
|
const {
|
||||||
usePlaybackStore(
|
mediaSegments,
|
||||||
useShallow((state) => ({
|
currentSegmentIndex,
|
||||||
mediaSegments: state.metadata.mediaSegments,
|
skipSegment,
|
||||||
currentSegmentIndex: state.nextSegmentIndex - 1,
|
activeSegmentId,
|
||||||
skipSegment: state.skipSegment,
|
isUserHovering,
|
||||||
activeSegmentId: state.activeSegmentId,
|
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 (
|
if (
|
||||||
!mediaSegments?.Items?.length ||
|
!mediaSegments?.Items?.length ||
|
||||||
currentSegmentIndex < 0 ||
|
currentSegmentIndex < 0 ||
|
||||||
!activeSegmentId
|
!activeSegmentId
|
||||||
) {
|
) {
|
||||||
return <></>; // No segments to skip
|
return null; // No segments to skip
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -33,8 +40,10 @@ const SkipSegmentButton = () => {
|
|||||||
color="white"
|
color="white"
|
||||||
style={{
|
style={{
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
bottom: "18vh",
|
bottom:
|
||||||
|
isUserHovering || !isPlayerPlaying || isUserSeeking ? "18vh" : "2em",
|
||||||
right: "2em",
|
right: "2em",
|
||||||
|
transition: "bottom 0.3s ease-in-out",
|
||||||
zIndex: 10000,
|
zIndex: 10000,
|
||||||
}}
|
}}
|
||||||
onClick={skipSegment}
|
onClick={skipSegment}
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ import ProgressDislay from "./ProgressDisplay";
|
|||||||
const VOLUME_SCROLL_INTERVAL = 0.02;
|
const VOLUME_SCROLL_INTERVAL = 0.02;
|
||||||
|
|
||||||
type VideoPlayerControlsProps = {
|
type VideoPlayerControlsProps = {
|
||||||
isVisible: boolean;
|
// isVisible: boolean;
|
||||||
onHover?: (event: MouseEvent<HTMLDivElement>) => void;
|
onHover?: (event: MouseEvent<HTMLDivElement>) => void;
|
||||||
onLeave?: (event: MouseEvent<HTMLDivElement>) => void;
|
onLeave?: (event: MouseEvent<HTMLDivElement>) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const VideoPlayerControls = ({
|
const VideoPlayerControls = ({
|
||||||
isVisible,
|
// isVisible,
|
||||||
onHover,
|
onHover,
|
||||||
onLeave,
|
onLeave,
|
||||||
}: VideoPlayerControlsProps) => {
|
}: VideoPlayerControlsProps) => {
|
||||||
@@ -69,6 +69,7 @@ const VideoPlayerControls = ({
|
|||||||
increaseVolumeByStep,
|
increaseVolumeByStep,
|
||||||
decreaseVolumeByStep,
|
decreaseVolumeByStep,
|
||||||
getCurrentTime,
|
getCurrentTime,
|
||||||
|
isUserHovering,
|
||||||
} = usePlaybackStore(
|
} = usePlaybackStore(
|
||||||
useShallow((state) => ({
|
useShallow((state) => ({
|
||||||
mediaSourceId: state.mediaSource.id,
|
mediaSourceId: state.mediaSource.id,
|
||||||
@@ -90,6 +91,7 @@ const VideoPlayerControls = ({
|
|||||||
increaseVolumeByStep: state.increaseVolumeByStep,
|
increaseVolumeByStep: state.increaseVolumeByStep,
|
||||||
decreaseVolumeByStep: state.decreaseVolumeByStep,
|
decreaseVolumeByStep: state.decreaseVolumeByStep,
|
||||||
getCurrentTime: state.getCurrentTime,
|
getCurrentTime: state.getCurrentTime,
|
||||||
|
isUserHovering: state.playerState.isUserHovering,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -168,7 +170,7 @@ const VideoPlayerControls = ({
|
|||||||
return (
|
return (
|
||||||
<motion.div
|
<motion.div
|
||||||
className={
|
className={
|
||||||
isVisible || isUserSeeking || !isPlayerPlaying
|
isUserHovering || isUserSeeking || !isPlayerPlaying
|
||||||
? "video-player-osd hovering"
|
? "video-player-osd hovering"
|
||||||
: "video-player-osd"
|
: "video-player-osd"
|
||||||
}
|
}
|
||||||
@@ -179,7 +181,7 @@ const VideoPlayerControls = ({
|
|||||||
opacity: 0,
|
opacity: 0,
|
||||||
}}
|
}}
|
||||||
animate={{
|
animate={{
|
||||||
opacity: isVisible || isUserSeeking || !isPlayerPlaying ? 1 : 0,
|
opacity: isUserHovering || isUserSeeking || !isPlayerPlaying ? 1 : 0,
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
zIndex: 2,
|
zIndex: 2,
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ export function VideoPlayer() {
|
|||||||
setIsBuffering,
|
setIsBuffering,
|
||||||
registerPlayerActions,
|
registerPlayerActions,
|
||||||
toggleIsPlayerFullscreen,
|
toggleIsPlayerFullscreen,
|
||||||
|
setIsUserHovering,
|
||||||
} = usePlaybackStore(
|
} = usePlaybackStore(
|
||||||
useShallow((state) => ({
|
useShallow((state) => ({
|
||||||
itemId: state.metadata.item?.Id,
|
itemId: state.metadata.item?.Id,
|
||||||
@@ -132,6 +133,7 @@ export function VideoPlayer() {
|
|||||||
playbackStream: state.playbackStream,
|
playbackStream: state.playbackStream,
|
||||||
setIsBuffering: state.setIsBuffering,
|
setIsBuffering: state.setIsBuffering,
|
||||||
registerPlayerActions: state.registerPlayerActions,
|
registerPlayerActions: state.registerPlayerActions,
|
||||||
|
setIsUserHovering: state.setIsUserHovering,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -372,7 +374,7 @@ export function VideoPlayer() {
|
|||||||
// }
|
// }
|
||||||
// }, [playerVolume]);
|
// }, [playerVolume]);
|
||||||
|
|
||||||
const [areControlsVisible, setAreControlsVisible] = useState(false);
|
const [_areControlsVisible, _setAreControlsVisiblee] = useState(false);
|
||||||
const idleTimerRef = useRef<NodeJS.Timeout | null>(null);
|
const idleTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
// Function to clear the existing idle timer
|
// Function to clear the existing idle timer
|
||||||
@@ -388,7 +390,7 @@ export function VideoPlayer() {
|
|||||||
clearIdleTimer();
|
clearIdleTimer();
|
||||||
// Set a timer to hide the controls after 3 seconds of inactivity
|
// Set a timer to hide the controls after 3 seconds of inactivity
|
||||||
idleTimerRef.current = setTimeout(() => {
|
idleTimerRef.current = setTimeout(() => {
|
||||||
setAreControlsVisible(false);
|
setIsUserHovering(false);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}, [clearIdleTimer]);
|
}, [clearIdleTimer]);
|
||||||
|
|
||||||
@@ -396,14 +398,14 @@ export function VideoPlayer() {
|
|||||||
|
|
||||||
const handleMouseMove = useCallback(() => {
|
const handleMouseMove = useCallback(() => {
|
||||||
// When the mouse moves, show the controls and restart the idle timer.
|
// When the mouse moves, show the controls and restart the idle timer.
|
||||||
setAreControlsVisible(true);
|
setIsUserHovering(true);
|
||||||
startIdleTimer();
|
startIdleTimer();
|
||||||
}, [startIdleTimer]);
|
}, [startIdleTimer]);
|
||||||
|
|
||||||
const handleMouseLeave = useCallback(() => {
|
const handleMouseLeave = useCallback(() => {
|
||||||
// When the mouse leaves the player, clear the timer and hide the controls.
|
// When the mouse leaves the player, clear the timer and hide the controls.
|
||||||
clearIdleTimer();
|
clearIdleTimer();
|
||||||
setAreControlsVisible(false);
|
setIsUserHovering(false);
|
||||||
}, [clearIdleTimer]);
|
}, [clearIdleTimer]);
|
||||||
|
|
||||||
const handleOnBuffer = useCallback(() => {
|
const handleOnBuffer = useCallback(() => {
|
||||||
@@ -438,7 +440,7 @@ export function VideoPlayer() {
|
|||||||
>
|
>
|
||||||
<LoadingIndicator />
|
<LoadingIndicator />
|
||||||
<VideoPlayerControls
|
<VideoPlayerControls
|
||||||
isVisible={areControlsVisible}
|
// isVisible={areControlsVisible}
|
||||||
onHover={handleMouseMove}
|
onHover={handleMouseMove}
|
||||||
onLeave={handleMouseLeave}
|
onLeave={handleMouseLeave}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user