Update TrailerModal.tsx

This commit is contained in:
CK 2026-03-05 16:34:00 +00:00 committed by GitHub
parent 16a9c5c41d
commit 86477b594a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -159,35 +159,28 @@ const TrailerModal: React.FC<TrailerModalProps> = memo(({
const handleVideoError = useCallback((error: any) => { const handleVideoError = useCallback((error: any) => {
logger.error('TrailerModal', 'Video error:', error); logger.error('TrailerModal', 'Video error:', error);
// Check if this is a permission/network error that might benefit from retry
const errorCode = error?.error?.code; const errorCode = error?.error?.code;
const isRetryableError = errorCode === -1102 || errorCode === -1009 || errorCode === -1005; const isRetryableError = errorCode === -1102 || errorCode === -1009 || errorCode === -1005;
if (isRetryableError && retryCount < 2) { if (isRetryableError && retryCount < 2) {
// Silent retry - increment count and try again
logger.info('TrailerModal', `Retrying video load (attempt ${retryCount + 1}/2)`); logger.info('TrailerModal', `Retrying video load (attempt ${retryCount + 1}/2)`);
setRetryCount(prev => prev + 1); setRetryCount(prev => prev + 1);
// Small delay before retry to avoid rapid-fire attempts // Capture current URL before clearing it
setTrailerUrl(current => {
const urlToRestore = current;
setTimeout(() => { setTimeout(() => {
if (videoRef.current) { setTrailerUrl(urlToRestore);
// Force video to reload by changing the source briefly }, 500);
setTrailerUrl(null); return null; // Clear first to force remount
setTimeout(() => { });
if (trailerUrl) {
setTrailerUrl(trailerUrl);
}
}, 100);
}
}, 1000);
return; return;
} }
// After 2 retries or for non-retryable errors, show the error
logger.error('TrailerModal', 'Video error after retries or non-retryable:', error); logger.error('TrailerModal', 'Video error after retries or non-retryable:', error);
setError('Unable to play trailer. Please try again.'); setError('Unable to play trailer. Please try again.');
setLoading(false); setLoading(false);
}, [retryCount, trailerUrl]); }, [retryCount]);
const handleTrailerEnd = useCallback(() => { const handleTrailerEnd = useCallback(() => {
setIsPlaying(false); setIsPlaying(false);