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) => {
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 isRetryableError = errorCode === -1102 || errorCode === -1009 || errorCode === -1005;
if (isRetryableError && retryCount < 2) {
// Silent retry - increment count and try again
logger.info('TrailerModal', `Retrying video load (attempt ${retryCount + 1}/2)`);
setRetryCount(prev => prev + 1);
// Small delay before retry to avoid rapid-fire attempts
setTimeout(() => {
if (videoRef.current) {
// Force video to reload by changing the source briefly
setTrailerUrl(null);
setTimeout(() => {
if (trailerUrl) {
setTrailerUrl(trailerUrl);
}
}, 100);
}
}, 1000);
// Capture current URL before clearing it
setTrailerUrl(current => {
const urlToRestore = current;
setTimeout(() => {
setTrailerUrl(urlToRestore);
}, 500);
return null; // Clear first to force remount
});
return;
}
// After 2 retries or for non-retryable errors, show the error
logger.error('TrailerModal', 'Video error after retries or non-retryable:', error);
setError('Unable to play trailer. Please try again.');
setLoading(false);
}, [retryCount, trailerUrl]);
}, [retryCount]);
const handleTrailerEnd = useCallback(() => {
setIsPlaying(false);