mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-04-21 00:32:04 +00:00
major bug fix
This commit is contained in:
parent
3608493518
commit
27b52a5a45
2 changed files with 53 additions and 21 deletions
|
|
@ -755,6 +755,15 @@ const HeroSection: React.FC<HeroSectionProps> = memo(({
|
||||||
trailerOpacity.value = withTiming(1, { duration: 500 });
|
trailerOpacity.value = withTiming(1, { duration: 500 });
|
||||||
}, [thumbnailOpacity, trailerOpacity, trailerPreloaded]);
|
}, [thumbnailOpacity, trailerOpacity, trailerPreloaded]);
|
||||||
|
|
||||||
|
// Ensure trailer state is properly synchronized when trailer becomes ready
|
||||||
|
useEffect(() => {
|
||||||
|
if (trailerReady && settings?.showTrailers && !globalTrailerPlaying) {
|
||||||
|
// If trailer is ready but not playing, start it
|
||||||
|
logger.info('HeroSection', 'Starting trailer after it became ready');
|
||||||
|
setTrailerPlaying(true);
|
||||||
|
}
|
||||||
|
}, [trailerReady, settings?.showTrailers, globalTrailerPlaying, setTrailerPlaying]);
|
||||||
|
|
||||||
// Handle fullscreen toggle
|
// Handle fullscreen toggle
|
||||||
const handleFullscreenToggle = useCallback(async () => {
|
const handleFullscreenToggle = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -1008,37 +1017,53 @@ const HeroSection: React.FC<HeroSectionProps> = memo(({
|
||||||
if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
|
if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
|
||||||
// App came to foreground
|
// App came to foreground
|
||||||
logger.info('HeroSection', 'App came to foreground');
|
logger.info('HeroSection', 'App came to foreground');
|
||||||
|
// Don't automatically resume trailer - let TrailerPlayer handle it
|
||||||
} else if (appState.current === 'active' && nextAppState.match(/inactive|background/)) {
|
} else if (appState.current === 'active' && nextAppState.match(/inactive|background/)) {
|
||||||
// App going to background - pause heavy operations
|
// App going to background - only pause if trailer is actually playing
|
||||||
logger.info('HeroSection', 'App going to background - pausing operations');
|
logger.info('HeroSection', 'App going to background - pausing operations');
|
||||||
setTrailerPlaying(false);
|
// Only pause if trailer is currently playing to avoid unnecessary state changes
|
||||||
|
if (globalTrailerPlaying) {
|
||||||
|
setTrailerPlaying(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
appState.current = nextAppState;
|
appState.current = nextAppState;
|
||||||
};
|
};
|
||||||
|
|
||||||
const subscription = AppState.addEventListener('change', handleAppStateChange);
|
const subscription = AppState.addEventListener('change', handleAppStateChange);
|
||||||
return () => subscription?.remove();
|
return () => subscription?.remove();
|
||||||
}, [setTrailerPlaying]);
|
}, [setTrailerPlaying, globalTrailerPlaying]);
|
||||||
|
|
||||||
// Navigation focus effect to stop trailer when navigating away
|
// Navigation focus effect - improved to prevent trailer interruption
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
// Screen is focused
|
// Screen is focused - ensure trailer can play if it should be playing
|
||||||
logger.info('HeroSection', 'Screen focused');
|
logger.info('HeroSection', 'Screen focused');
|
||||||
|
|
||||||
|
// Small delay to ensure the screen is fully focused before checking trailer state
|
||||||
|
const focusTimer = setTimeout(() => {
|
||||||
|
// If trailer should be playing but isn't, resume it
|
||||||
|
if (settings?.showTrailers && trailerReady && !globalTrailerPlaying) {
|
||||||
|
logger.info('HeroSection', 'Resuming trailer after screen focus');
|
||||||
|
setTrailerPlaying(true);
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
// Screen is unfocused - stop trailer playback
|
clearTimeout(focusTimer);
|
||||||
logger.info('HeroSection', 'Screen unfocused - stopping trailer');
|
// Don't automatically stop trailer when component unmounts
|
||||||
setTrailerPlaying(false);
|
// Let the new hero section (if any) take control of trailer state
|
||||||
|
// This prevents the trailer from stopping when navigating between screens
|
||||||
|
logger.info('HeroSection', 'Screen unfocused - not stopping trailer automatically');
|
||||||
};
|
};
|
||||||
}, [setTrailerPlaying])
|
}, [settings?.showTrailers, trailerReady, globalTrailerPlaying, setTrailerPlaying])
|
||||||
);
|
);
|
||||||
|
|
||||||
// Memory management and cleanup
|
// Memory management and cleanup
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
// Stop trailer playback when component unmounts
|
// Don't stop trailer playback when component unmounts
|
||||||
setTrailerPlaying(false);
|
// Let the new hero section (if any) take control of trailer state
|
||||||
|
// This prevents the trailer from stopping when navigating between screens
|
||||||
|
|
||||||
// Reset animation values on unmount to prevent memory leaks
|
// Reset animation values on unmount to prevent memory leaks
|
||||||
try {
|
try {
|
||||||
|
|
@ -1062,7 +1087,7 @@ const HeroSection: React.FC<HeroSectionProps> = memo(({
|
||||||
|
|
||||||
interactionComplete.current = false;
|
interactionComplete.current = false;
|
||||||
};
|
};
|
||||||
}, [imageOpacity, imageLoadOpacity, shimmerOpacity, trailerOpacity, thumbnailOpacity, actionButtonsOpacity, titleCardTranslateY, genreOpacity, watchProgressOpacity, buttonsOpacity, buttonsTranslateY, logoOpacity, heroOpacity, heroHeight, setTrailerPlaying]);
|
}, [imageOpacity, imageLoadOpacity, shimmerOpacity, trailerOpacity, thumbnailOpacity, actionButtonsOpacity, titleCardTranslateY, genreOpacity, watchProgressOpacity, buttonsOpacity, buttonsTranslateY, logoOpacity, heroOpacity, heroHeight]);
|
||||||
|
|
||||||
// Development-only performance monitoring
|
// Development-only performance monitoring
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
|
|
@ -107,10 +107,17 @@ const TrailerPlayer = React.forwardRef<any, TrailerPlayerProps>(({
|
||||||
logger.info('TrailerPlayer', 'App going to background - pausing video');
|
logger.info('TrailerPlayer', 'App going to background - pausing video');
|
||||||
setIsPlaying(false);
|
setIsPlaying(false);
|
||||||
} else if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
|
} else if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
|
||||||
// App coming to foreground - resume if it was playing
|
// App coming to foreground - resume if it was playing and autoPlay is enabled
|
||||||
logger.info('TrailerPlayer', 'App coming to foreground');
|
logger.info('TrailerPlayer', 'App coming to foreground');
|
||||||
|
// Only resume if autoPlay is true and component is still mounted
|
||||||
|
// Add a small delay to ensure the app is fully active
|
||||||
if (autoPlay && isComponentMounted) {
|
if (autoPlay && isComponentMounted) {
|
||||||
setIsPlaying(true);
|
setTimeout(() => {
|
||||||
|
if (isComponentMounted) {
|
||||||
|
logger.info('TrailerPlayer', 'Resuming video after app foreground');
|
||||||
|
setIsPlaying(true);
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
appState.current = nextAppState;
|
appState.current = nextAppState;
|
||||||
|
|
@ -130,6 +137,13 @@ const TrailerPlayer = React.forwardRef<any, TrailerPlayerProps>(({
|
||||||
};
|
};
|
||||||
}, [cleanupVideo]);
|
}, [cleanupVideo]);
|
||||||
|
|
||||||
|
// Handle autoPlay prop changes to keep internal state synchronized
|
||||||
|
useEffect(() => {
|
||||||
|
if (isComponentMounted) {
|
||||||
|
setIsPlaying(autoPlay);
|
||||||
|
}
|
||||||
|
}, [autoPlay, isComponentMounted]);
|
||||||
|
|
||||||
const showControlsWithTimeout = useCallback(() => {
|
const showControlsWithTimeout = useCallback(() => {
|
||||||
if (!isComponentMounted) return;
|
if (!isComponentMounted) return;
|
||||||
|
|
||||||
|
|
@ -244,13 +258,6 @@ const TrailerPlayer = React.forwardRef<any, TrailerPlayerProps>(({
|
||||||
}
|
}
|
||||||
}, [muted, isComponentMounted]);
|
}, [muted, isComponentMounted]);
|
||||||
|
|
||||||
// Sync internal playing state with autoPlay prop
|
|
||||||
useEffect(() => {
|
|
||||||
if (isComponentMounted) {
|
|
||||||
setIsPlaying(autoPlay);
|
|
||||||
}
|
|
||||||
}, [autoPlay, isComponentMounted]);
|
|
||||||
|
|
||||||
// Cleanup timeout and animated values on unmount
|
// Cleanup timeout and animated values on unmount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue