disabled android player brightness control temporarily

This commit is contained in:
tapframe 2026-01-26 17:17:24 +05:30
parent 2417bf548a
commit a8f10fbcd8
4 changed files with 74 additions and 116 deletions

View file

@ -176,8 +176,7 @@ const AndroidVideoPlayer: React.FC = () => {
const openingAnimation = useOpeningAnimation(backdrop, metadata);
const [volume, setVolume] = useState(1.0);
const [brightness, setBrightness] = useState(1.0);
const setupHook = usePlayerSetup(playerState.setScreenDimensions, setVolume, setBrightness, playerState.paused);
const setupHook = usePlayerSetup(playerState.setScreenDimensions, setVolume, playerState.paused);
const controlsHook = usePlayerControls(
mpvPlayerRef,
@ -218,8 +217,6 @@ const AndroidVideoPlayer: React.FC = () => {
const gestureControls = usePlayerGestureControls({
volume,
setVolume,
brightness,
setBrightness,
volumeRange: { min: 0, max: 1 },
volumeSensitivity: 0.006,
brightnessSensitivity: 0.004,
@ -873,7 +870,6 @@ const AndroidVideoPlayer: React.FC = () => {
showControls={playerState.showControls}
hideControls={hideControls}
volume={volume}
brightness={brightness}
controlsTimeout={controlsTimeout}
resizeMode={playerState.resizeMode}
/>

View file

@ -2,7 +2,7 @@ import { useEffect, useRef } from 'react';
import { StatusBar, Platform, Dimensions, AppState } from 'react-native';
import RNImmersiveMode from 'react-native-immersive-mode';
import * as NavigationBar from 'expo-navigation-bar';
import * as Brightness from 'expo-brightness';
import { activateKeepAwakeAsync, deactivateKeepAwake } from 'expo-keep-awake';
import { logger } from '../../../../utils/logger';
import { useFocusEffect } from '@react-navigation/native';
@ -13,12 +13,10 @@ const DEBUG_MODE = false;
export const usePlayerSetup = (
setScreenDimensions: (dim: any) => void,
setVolume: (vol: number) => void,
setBrightness: (bri: number) => void,
paused: boolean
) => {
const originalAppBrightnessRef = useRef<number | null>(null);
const originalSystemBrightnessRef = useRef<number | null>(null);
const originalSystemBrightnessModeRef = useRef<number | null>(null);
const isAppBackgrounded = useRef(false);
// Prevent screen sleep while playing
@ -85,49 +83,9 @@ export const usePlayerSetup = (
// Initialize volume (default to 1.0)
setVolume(1.0);
// Initialize Brightness
const initBrightness = async () => {
try {
if (Platform.OS === 'android') {
try {
const [sysBright, sysMode] = await Promise.all([
(Brightness as any).getSystemBrightnessAsync?.(),
(Brightness as any).getSystemBrightnessModeAsync?.()
]);
originalSystemBrightnessRef.current = typeof sysBright === 'number' ? sysBright : null;
originalSystemBrightnessModeRef.current = typeof sysMode === 'number' ? sysMode : null;
} catch (e) {
// ignore
}
}
const currentBrightness = await Brightness.getBrightnessAsync();
originalAppBrightnessRef.current = currentBrightness;
setBrightness(currentBrightness);
} catch (error) {
logger.warn('[usePlayerSetup] Error setting brightness', error);
setBrightness(1.0);
}
};
initBrightness();
return () => {
subscription?.remove();
disableImmersiveMode();
const restoreBrightness = async () => {
try {
if (Platform.OS === 'android') {
}
if (originalAppBrightnessRef.current !== null) {
await Brightness.setBrightnessAsync(originalAppBrightnessRef.current);
setBrightness(originalAppBrightnessRef.current);
}
} catch (e) {
logger.warn('[usePlayerSetup] Error restoring brightness', e);
}
};
restoreBrightness();
};
}, []);

View file

@ -19,7 +19,7 @@ interface GestureControlsProps {
showControls: boolean;
hideControls: () => void;
volume: number;
brightness: number;
brightness?: number;
controlsTimeout: React.MutableRefObject<NodeJS.Timeout | null>;
resizeMode?: string;
}
@ -34,7 +34,7 @@ export const GestureControls: React.FC<GestureControlsProps> = ({
showControls,
hideControls,
volume,
brightness,
brightness = 0.5,
controlsTimeout,
resizeMode = 'contain'
}) => {

View file

@ -6,8 +6,8 @@ import * as Brightness from 'expo-brightness';
interface GestureControlConfig {
volume: number;
setVolume: (value: number) => void;
brightness: number;
setBrightness: (value: number) => void;
brightness?: number;
setBrightness?: (value: number) => void;
volumeRange?: { min: number; max: number }; // Default: { min: 0, max: 1 }
volumeSensitivity?: number; // Default: 0.006 (iOS), 0.0084 (Android with 1.4x multiplier)
brightnessSensitivity?: number; // Default: 0.004 (iOS), 0.0056 (Android with 1.4x multiplier)
@ -20,69 +20,69 @@ export const usePlayerGestureControls = (config: GestureControlConfig) => {
const [showVolumeOverlay, setShowVolumeOverlay] = useState(false);
const [showBrightnessOverlay, setShowBrightnessOverlay] = useState(false);
const [showResizeModeOverlay, setShowResizeModeOverlay] = useState(false);
// Animated values
const volumeGestureTranslateY = useRef(new Animated.Value(0)).current;
const brightnessGestureTranslateY = useRef(new Animated.Value(0)).current;
const volumeOverlayOpacity = useRef(new Animated.Value(0)).current;
const brightnessOverlayOpacity = useRef(new Animated.Value(0)).current;
const resizeModeOverlayOpacity = useRef(new Animated.Value(0)).current;
// Tracking refs
const lastVolumeGestureY = useRef(0);
const lastBrightnessGestureY = useRef(0);
const volumeOverlayTimeout = useRef<NodeJS.Timeout | null>(null);
const brightnessOverlayTimeout = useRef<NodeJS.Timeout | null>(null);
const resizeModeOverlayTimeout = useRef<NodeJS.Timeout | null>(null);
// Extract config with defaults and platform adjustments
const volumeRange = config.volumeRange || { min: 0, max: 1 };
const baseVolumeSensitivity = config.volumeSensitivity || 0.006;
const baseBrightnessSensitivity = config.brightnessSensitivity || 0.004;
const overlayTimeout = config.overlayTimeout || 1500;
// Platform-specific sensitivity adjustments
// Android needs higher sensitivity due to different touch handling
const platformMultiplier = Platform.OS === 'android' ? 1.6 : 1.0;
const volumeSensitivity = baseVolumeSensitivity * platformMultiplier;
const brightnessSensitivity = baseBrightnessSensitivity * platformMultiplier;
// Volume gesture handler
const onVolumeGestureEvent = Animated.event(
[{ nativeEvent: { translationY: volumeGestureTranslateY } }],
{
{
useNativeDriver: false,
listener: (event: PanGestureHandlerGestureEvent) => {
const { translationY, state } = event.nativeEvent;
if (state === State.ACTIVE) {
// Auto-initialize on first active frame
if (Math.abs(translationY) < 5 && Math.abs(lastVolumeGestureY.current - translationY) > 20) {
lastVolumeGestureY.current = translationY;
return;
}
// Calculate delta from last position
const deltaY = -(translationY - lastVolumeGestureY.current);
lastVolumeGestureY.current = translationY;
// Normalize sensitivity based on volume range
const rangeMultiplier = volumeRange.max - volumeRange.min;
const volumeChange = deltaY * volumeSensitivity * rangeMultiplier;
const newVolume = Math.max(volumeRange.min, Math.min(volumeRange.max, config.volume + volumeChange));
config.setVolume(newVolume);
if (config.debugMode) {
console.log(`[GestureControls] Volume set to: ${newVolume} (Platform: ${Platform.OS}, Sensitivity: ${volumeSensitivity})`);
}
// Show overlay
if (!showVolumeOverlay) {
setShowVolumeOverlay(true);
volumeOverlayOpacity.setValue(1);
}
// Reset hide timer
if (volumeOverlayTimeout.current) {
clearTimeout(volumeOverlayTimeout.current);
@ -98,55 +98,59 @@ export const usePlayerGestureControls = (config: GestureControlConfig) => {
}
}
);
// Brightness gesture handler
const onBrightnessGestureEvent = Animated.event(
[{ nativeEvent: { translationY: brightnessGestureTranslateY } }],
{
useNativeDriver: false,
listener: (event: PanGestureHandlerGestureEvent) => {
const { translationY, state } = event.nativeEvent;
if (state === State.ACTIVE) {
// Auto-initialize
if (Math.abs(translationY) < 5 && Math.abs(lastBrightnessGestureY.current - translationY) > 20) {
// Brightness gesture handler - only active if brightness is provided
const onBrightnessGestureEvent = config.brightness !== undefined && config.setBrightness
? Animated.event(
[{ nativeEvent: { translationY: brightnessGestureTranslateY } }],
{
useNativeDriver: false,
listener: (event: PanGestureHandlerGestureEvent) => {
const { translationY, state } = event.nativeEvent;
if (state === State.ACTIVE) {
// Auto-initialize
if (Math.abs(translationY) < 5 && Math.abs(lastBrightnessGestureY.current - translationY) > 20) {
lastBrightnessGestureY.current = translationY;
return;
}
const deltaY = -(translationY - lastBrightnessGestureY.current);
lastBrightnessGestureY.current = translationY;
return;
const brightnessSensitivity = (config.brightnessSensitivity || 0.004) * platformMultiplier;
const brightnessChange = deltaY * brightnessSensitivity;
const currentBrightness = config.brightness as number; // Safe cast as we checked undefined
const newBrightness = Math.max(0, Math.min(1, currentBrightness + brightnessChange));
config.setBrightness!(newBrightness);
Brightness.setBrightnessAsync(newBrightness).catch(() => { });
if (config.debugMode) {
console.log(`[GestureControls] Device brightness set to: ${newBrightness} (Platform: ${Platform.OS}, Sensitivity: ${brightnessSensitivity})`);
}
if (!showBrightnessOverlay) {
setShowBrightnessOverlay(true);
brightnessOverlayOpacity.setValue(1);
}
if (brightnessOverlayTimeout.current) {
clearTimeout(brightnessOverlayTimeout.current);
}
brightnessOverlayTimeout.current = setTimeout(() => {
Animated.timing(brightnessOverlayOpacity, {
toValue: 0,
duration: 250,
useNativeDriver: true,
}).start(() => setShowBrightnessOverlay(false));
}, overlayTimeout);
}
const deltaY = -(translationY - lastBrightnessGestureY.current);
lastBrightnessGestureY.current = translationY;
const brightnessChange = deltaY * brightnessSensitivity;
const newBrightness = Math.max(0, Math.min(1, config.brightness + brightnessChange));
config.setBrightness(newBrightness);
Brightness.setBrightnessAsync(newBrightness).catch(() => {});
if (config.debugMode) {
console.log(`[GestureControls] Device brightness set to: ${newBrightness} (Platform: ${Platform.OS}, Sensitivity: ${brightnessSensitivity})`);
}
if (!showBrightnessOverlay) {
setShowBrightnessOverlay(true);
brightnessOverlayOpacity.setValue(1);
}
if (brightnessOverlayTimeout.current) {
clearTimeout(brightnessOverlayTimeout.current);
}
brightnessOverlayTimeout.current = setTimeout(() => {
Animated.timing(brightnessOverlayOpacity, {
toValue: 0,
duration: 250,
useNativeDriver: true,
}).start(() => setShowBrightnessOverlay(false));
}, overlayTimeout);
}
}
}
);
)
: undefined;
// Cleanup function
const cleanup = () => {
if (volumeOverlayTimeout.current) {
@ -180,12 +184,12 @@ export const usePlayerGestureControls = (config: GestureControlConfig) => {
}, overlayTimeout);
});
};
return {
// Gesture handlers
onVolumeGestureEvent,
onBrightnessGestureEvent,
// Overlay state
showVolumeOverlay,
showBrightnessOverlay,
@ -193,10 +197,10 @@ export const usePlayerGestureControls = (config: GestureControlConfig) => {
volumeOverlayOpacity,
brightnessOverlayOpacity,
resizeModeOverlayOpacity,
// Overlay functions
showResizeModeOverlayFn,
// Cleanup
cleanup,
};