mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-03-11 17:45:38 +00:00
Merge pull request #608 from chrisk325/patch-16
fix edge case trailer unmount logic
This commit is contained in:
commit
237bf51b66
3 changed files with 15 additions and 18 deletions
|
|
@ -1144,6 +1144,7 @@ const HeroSection: React.FC<HeroSectionProps> = memo(({
|
||||||
setTrailerError(false);
|
setTrailerError(false);
|
||||||
setTrailerReady(false);
|
setTrailerReady(false);
|
||||||
setTrailerPreloaded(false);
|
setTrailerPreloaded(false);
|
||||||
|
startedOnReadyRef.current = false;
|
||||||
|
|
||||||
// Small delay to avoid blocking the UI render
|
// Small delay to avoid blocking the UI render
|
||||||
timerId = setTimeout(async () => {
|
timerId = setTimeout(async () => {
|
||||||
|
|
|
||||||
|
|
@ -159,28 +159,19 @@ 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);
|
||||||
|
|
||||||
const errorCode = error?.error?.code;
|
if (retryCount < 2) {
|
||||||
const isRetryableError = errorCode === -1102 || errorCode === -1009 || errorCode === -1005;
|
logger.info('TrailerModal', `Re-extracting trailer (attempt ${retryCount + 1}/2)`);
|
||||||
|
|
||||||
if (isRetryableError && retryCount < 2) {
|
|
||||||
logger.info('TrailerModal', `Retrying video load (attempt ${retryCount + 1}/2)`);
|
|
||||||
setRetryCount(prev => prev + 1);
|
setRetryCount(prev => prev + 1);
|
||||||
|
// Invalidate cache so loadTrailer gets a fresh URL, not the same bad one
|
||||||
// Capture current URL before clearing it
|
if (trailer?.key) TrailerService.invalidateCache(trailer.key);
|
||||||
setTrailerUrl(current => {
|
loadTrailer();
|
||||||
const urlToRestore = current;
|
|
||||||
setTimeout(() => {
|
|
||||||
setTrailerUrl(urlToRestore);
|
|
||||||
}, 500);
|
|
||||||
return null; // Clear first to force remount
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error('TrailerModal', 'Video error after retries or non-retryable:', error);
|
logger.error('TrailerModal', 'Video error after retries:', error);
|
||||||
setError('Unable to play trailer. Please try again.');
|
setError('Unable to play trailer. Please try again.');
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}, [retryCount]);
|
}, [retryCount, loadTrailer, trailer?.key]);
|
||||||
|
|
||||||
const handleTrailerEnd = useCallback(() => {
|
const handleTrailerEnd = useCallback(() => {
|
||||||
setIsPlaying(false);
|
setIsPlaying(false);
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ interface CacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TrailerService {
|
export class TrailerService {
|
||||||
// Cache for 3 minutes — just enough to avoid re-extracting on quick re-renders
|
// Cache for 5 seconds — just enough to avoid re-extracting on quick re-renders
|
||||||
private static readonly CACHE_TTL_MS = 30 * 1000;
|
private static readonly CACHE_TTL_MS = 5 * 1000;
|
||||||
private static urlCache = new Map<string, CacheEntry>();
|
private static urlCache = new Map<string, CacheEntry>();
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
@ -114,6 +114,11 @@ export class TrailerService {
|
||||||
return { url, title, year };
|
return { url, title, year };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static invalidateCache(videoId: string): void {
|
||||||
|
this.urlCache.delete(videoId);
|
||||||
|
logger.info('TrailerService', `Cache invalidated for videoId=${videoId}`);
|
||||||
|
}
|
||||||
|
|
||||||
static setUseLocalServer(_useLocal: boolean): void {}
|
static setUseLocalServer(_useLocal: boolean): void {}
|
||||||
|
|
||||||
static getServerStatus(): { usingLocal: boolean; localUrl: string } {
|
static getServerStatus(): { usingLocal: boolean; localUrl: string } {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue