Implement auto-hide for video player controls

Added auto-hide functionality for video player controls after 3 seconds of inactivity, with cleanup on unmount.
This commit is contained in:
AdityasahuX07 2025-12-31 18:56:32 +05:30 committed by GitHub
parent 4174fd2add
commit 8daca53be3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -233,6 +233,33 @@ const AndroidVideoPlayer: React.FC = () => {
}).start();
}, [playerState.showControls]);
// Auto-hide controls after 3 seconds of inactivity
useEffect(() => {
// Clear any existing timeout
if (controlsTimeout.current) {
clearTimeout(controlsTimeout.current);
controlsTimeout.current = null;
}
// Only set timeout if controls are visible and video is playing
if (playerState.showControls && !playerState.paused) {
controlsTimeout.current = setTimeout(() => {
// Don't hide if user is dragging the seek bar
if (!playerState.isDragging.current) {
playerState.setShowControls(false);
}
}, 3000); // 3 seconds delay
}
// Cleanup on unmount or when dependencies change
return () => {
if (controlsTimeout.current) {
clearTimeout(controlsTimeout.current);
controlsTimeout.current = null;
}
};
}, [playerState.showControls, playerState.paused, playerState.isDragging]);
useEffect(() => {
openingAnimation.startOpeningAnimation();
}, []);
@ -458,7 +485,10 @@ const AndroidVideoPlayer: React.FC = () => {
}, [playerState.currentTime, useCustomSubtitles, customSubtitles]);
const toggleControls = useCallback(() => {
playerState.setShowControls(prev => !prev);
playerState.setShowControls(prev => {
// If we're showing controls, the useEffect will handle the auto-hide timer
return !prev;
});
}, []);
const hideControls = useCallback(() => {
@ -880,6 +910,7 @@ const AndroidVideoPlayer: React.FC = () => {
visible={speedControl.showSpeedActivatedOverlay}
opacity={speedControl.speedActivatedOverlayOpacity}
speed={speedControl.holdToSpeedValue}
screenDimensions={playerState.screenDimensions}
/>
<PauseOverlay