From 9c12f9fc08b401e76570b9687a2eab232d944b65 Mon Sep 17 00:00:00 2001 From: tapframe Date: Mon, 28 Jul 2025 22:36:12 +0530 Subject: [PATCH] critical videoplayer bug fix --- local-scrapers-repo | 2 +- src/components/player/AndroidVideoPlayer.tsx | 29 ++++++++++++++--- src/components/player/VideoPlayer.tsx | 34 +++++++++++++++++--- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/local-scrapers-repo b/local-scrapers-repo index 46fce12a..63d560d5 160000 --- a/local-scrapers-repo +++ b/local-scrapers-repo @@ -1 +1 @@ -Subproject commit 46fce12a69ce684962a76893520e89fec18e0989 +Subproject commit 63d560d55f1a84a16318525ad4eb1db5162e059c diff --git a/src/components/player/AndroidVideoPlayer.tsx b/src/components/player/AndroidVideoPlayer.tsx index e822bfb8..2ceca4ab 100644 --- a/src/components/player/AndroidVideoPlayer.tsx +++ b/src/components/player/AndroidVideoPlayer.tsx @@ -518,10 +518,18 @@ const AndroidVideoPlayer: React.FC = () => { }; const onLoad = (data: any) => { - if (DEBUG_MODE) { - logger.log('[AndroidVideoPlayer] Video loaded:', data); - } - if (isMounted.current) { + try { + if (DEBUG_MODE) { + logger.log('[AndroidVideoPlayer] Video loaded:', data); + } + if (!isMounted.current) { + logger.warn('[AndroidVideoPlayer] Component unmounted, skipping onLoad'); + return; + } + if (!data) { + logger.error('[AndroidVideoPlayer] onLoad called with null/undefined data'); + return; + } const videoDuration = data.duration; if (data.duration > 0) { setDuration(videoDuration); @@ -541,6 +549,10 @@ const AndroidVideoPlayer: React.FC = () => { // Set aspect ratio from video dimensions if (data.naturalSize && data.naturalSize.width && data.naturalSize.height) { setVideoAspectRatio(data.naturalSize.width / data.naturalSize.height); + } else { + // Fallback to 16:9 aspect ratio if naturalSize is not available + setVideoAspectRatio(16 / 9); + logger.warn('[AndroidVideoPlayer] naturalSize not available, using default 16:9 aspect ratio'); } // Handle audio tracks @@ -585,6 +597,15 @@ const AndroidVideoPlayer: React.FC = () => { } completeOpeningAnimation(); controlsTimeout.current = setTimeout(hideControls, 5000); + } catch (error) { + logger.error('[AndroidVideoPlayer] Error in onLoad:', error); + // Set fallback values to prevent crashes + if (isMounted.current) { + setVideoAspectRatio(16 / 9); + setIsVideoLoaded(true); + setIsPlayerReady(true); + completeOpeningAnimation(); + } } }; diff --git a/src/components/player/VideoPlayer.tsx b/src/components/player/VideoPlayer.tsx index 9c1e0783..45b552b2 100644 --- a/src/components/player/VideoPlayer.tsx +++ b/src/components/player/VideoPlayer.tsx @@ -578,10 +578,18 @@ const VideoPlayer: React.FC = () => { }; const onLoad = (data: any) => { - if (DEBUG_MODE) { - logger.log('[VideoPlayer] Video loaded:', data); - } - if (isMounted.current) { + try { + if (DEBUG_MODE) { + logger.log('[VideoPlayer] Video loaded:', data); + } + if (!isMounted.current) { + logger.warn('[VideoPlayer] Component unmounted, skipping onLoad'); + return; + } + if (!data) { + logger.error('[VideoPlayer] onLoad called with null/undefined data'); + return; + } const videoDuration = data.duration / 1000; if (data.duration > 0) { setDuration(videoDuration); @@ -597,7 +605,14 @@ const VideoPlayer: React.FC = () => { } } } - setVideoAspectRatio(data.videoSize.width / data.videoSize.height); + // Set aspect ratio with null check for videoSize + if (data.videoSize && data.videoSize.width && data.videoSize.height) { + setVideoAspectRatio(data.videoSize.width / data.videoSize.height); + } else { + // Fallback to 16:9 aspect ratio if videoSize is not available + setVideoAspectRatio(16 / 9); + logger.warn('[VideoPlayer] videoSize not available, using default 16:9 aspect ratio'); + } if (data.audioTracks && data.audioTracks.length > 0) { setVlcAudioTracks(data.audioTracks); @@ -628,6 +643,15 @@ const VideoPlayer: React.FC = () => { } completeOpeningAnimation(); controlsTimeout.current = setTimeout(hideControls, 5000); + } catch (error) { + logger.error('[VideoPlayer] Error in onLoad:', error); + // Set fallback values to prevent crashes + if (isMounted.current) { + setVideoAspectRatio(16 / 9); + setIsVideoLoaded(true); + setIsPlayerReady(true); + completeOpeningAnimation(); + } } };