Removed duplicate error handlers

This commit is contained in:
Trevor Mears
2025-12-30 23:32:50 -08:00
parent 6d55a81d3d
commit 1f4e38b37e
+22 -14
View File
@@ -140,17 +140,28 @@ class VideoPlayer {
break; break;
} }
} else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) { } else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) {
// Non-fatal media error - try to recover (handles audio codec issues) // Non-fatal media error - try to recover with cooldown to prevent loops
console.log('Non-fatal media error:', data.details); const now = Date.now();
const timeSinceLastRecovery = now - (this.lastRecoveryAttempt || 0);
// Only attempt recovery if more than 2 seconds since last attempt
if (timeSinceLastRecovery > 2000) {
console.log('Non-fatal media error:', data.details, '- attempting recovery');
this.lastRecoveryAttempt = now;
this.hls.recoverMediaError(); this.hls.recoverMediaError();
// If fragParsingError, also seek forward slightly to skip corrupted segment // If fragParsingError, also seek forward slightly to skip corrupted segment
if (data.details === 'fragParsingError' && !this.video.paused && this.video.currentTime > 0) { if (data.details === 'fragParsingError' && !this.video.paused && this.video.currentTime > 0) {
console.log('[HLS] Seeking past corrupted segment...'); console.log('[HLS] Seeking past corrupted segment...');
setTimeout(() => { setTimeout(() => {
if (this.video && !this.video.paused) { if (this.video && !this.video.paused) {
this.video.currentTime += 0.5; this.video.currentTime += 1;
} }
}, 100); }, 200);
}
} else {
// Too many errors in quick succession - log but don't spam recovery
console.log('Non-fatal media error (cooldown):', data.details);
} }
} else if (data.details === 'bufferAppendError') { } else if (data.details === 'bufferAppendError') {
// Buffer errors during ad transitions - try recovery // Buffer errors during ad transitions - try recovery
@@ -336,21 +347,18 @@ class VideoPlayer {
this.hls.loadSource(this.getProxiedUrl(this.currentUrl)); this.hls.loadSource(this.getProxiedUrl(this.currentUrl));
this.hls.startLoad(); this.hls.startLoad();
} else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) { } else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) {
console.log('Media error, attempting recovery...'); // Fatal media error - try recovery with cooldown
const now = Date.now();
if (now - (this.lastRecoveryAttempt || 0) > 2000) {
console.log('Fatal media error, attempting recovery...');
this.lastRecoveryAttempt = now;
this.hls.recoverMediaError(); this.hls.recoverMediaError();
}
} else { } else {
console.error('Fatal HLS error:', data); console.error('Fatal HLS error:', data);
} }
} else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) { } else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) {
// Non-fatal media error - handle specific cases // Non-fatal media error - already handled in init(), skip duplicate handling
console.log('Non-fatal media error:', data.details);
if (data.details === 'bufferStalledError') {
// Buffer stalled - seek forward to unstick
console.log('[HLS] Buffer stalled, seeking to recover...');
if (!this.video.paused && this.video.currentTime > 0) {
this.video.currentTime += 1;
}
}
} }
}); });