From 81373a2bb2347ae28f8f0ef5945faa4192402030 Mon Sep 17 00:00:00 2001 From: tapframe Date: Sat, 9 Aug 2025 18:20:58 +0530 Subject: [PATCH] fixed xprime initial loading issue --- src/components/player/AndroidVideoPlayer.tsx | 54 ++++++++++++----- src/hooks/useDominantColor.ts | 64 ++++++++++++++------ src/screens/MetadataScreen.tsx | 63 ++++++++++++++----- src/screens/StreamsScreen.tsx | 1 + 4 files changed, 133 insertions(+), 49 deletions(-) diff --git a/src/components/player/AndroidVideoPlayer.tsx b/src/components/player/AndroidVideoPlayer.tsx index fa364537..f3d44ac1 100644 --- a/src/components/player/AndroidVideoPlayer.tsx +++ b/src/components/player/AndroidVideoPlayer.tsx @@ -175,6 +175,8 @@ const AndroidVideoPlayer: React.FC = () => { const [showSourcesModal, setShowSourcesModal] = useState(false); const [availableStreams, setAvailableStreams] = useState<{ [providerId: string]: { streams: any[]; addonName: string } }>(passedAvailableStreams || {}); const [currentStreamUrl, setCurrentStreamUrl] = useState(uri); + // Track a single silent retry per source to avoid loops + const retryAttemptRef = useRef(0); const [isChangingSource, setIsChangingSource] = useState(false); const [pendingSeek, setPendingSeek] = useState<{ position: number; shouldPlay: boolean } | null>(null); const [currentQuality, setCurrentQuality] = useState(quality); @@ -781,11 +783,41 @@ const AndroidVideoPlayer: React.FC = () => { return; } - // Check for specific AVFoundation server configuration errors - const isServerConfigError = error?.error?.code === -11850 || - error?.code === -11850 || - (error?.error?.localizedDescription && - error.error.localizedDescription.includes('server is not correctly configured')); + // Detect Xprime provider to enable a one-shot silent retry (warms upstream/cache) + const providerName = ((currentStreamProvider || streamProvider || '') as string).toLowerCase(); + const isXprimeProvider = providerName.includes('xprime'); + + // One-shot, silent retry without showing error UI + if (isXprimeProvider && retryAttemptRef.current < 1) { + retryAttemptRef.current = 1; + // Cache-bust to force a fresh fetch and warm upstream + const addRetryParam = (url: string) => { + const sep = url.includes('?') ? '&' : '?'; + return `${url}${sep}rn_retry_ts=${Date.now()}`; + }; + const bustedUrl = addRetryParam(currentStreamUrl); + logger.warn('[AndroidVideoPlayer] Silent retry for Xprime with cache-busted URL'); + // Ensure no modal is visible + if (errorTimeoutRef.current) { + clearTimeout(errorTimeoutRef.current); + errorTimeoutRef.current = null; + } + safeSetState(() => setShowErrorModal(false)); + // Brief pause to let the player reset + setPaused(true); + setTimeout(() => { + if (!isMounted.current) return; + setCurrentStreamUrl(bustedUrl); + setPaused(false); + }, 120); + return; // Do not proceed to show error UI + } + + // Check for specific AVFoundation server configuration errors (iOS) + const isServerConfigError = error?.error?.code === -11850 || + error?.code === -11850 || + (error?.error?.localizedDescription && + error.error.localizedDescription.includes('server is not correctly configured')); // Format error details for user display let errorMessage = 'An unknown error occurred'; @@ -1488,17 +1520,7 @@ const AndroidVideoPlayer: React.FC = () => {