forked from computertech/techdj
Improve listener error reporting and add auto-retry for empty buffers
This commit is contained in:
25
script.js
25
script.js
@@ -2397,9 +2397,28 @@ async function enableListenerAudio() {
|
|||||||
|
|
||||||
if (audioText) audioText.textContent = 'RETRY ENABLE';
|
if (audioText) audioText.textContent = 'RETRY ENABLE';
|
||||||
if (stashedStatus) {
|
if (stashedStatus) {
|
||||||
stashedStatus.textContent = '⚠️ ' + (error.message === 'Timeout waiting for audio data'
|
// Show the actual error message to help debugging
|
||||||
? 'No stream data yet. Is the DJ broadcasting?'
|
let errorMsg = error.name + ': ' + error.message;
|
||||||
: 'Browser blocked audio. Please click again.');
|
if (error.name === 'NotAllowedError') {
|
||||||
|
errorMsg = 'Browser blocked audio (NotAllowedError). Check permissions.';
|
||||||
|
} else if (error.name === 'NotSupportedError') {
|
||||||
|
errorMsg = 'Format not supported or buffer empty (NotSupportedError).';
|
||||||
|
}
|
||||||
|
|
||||||
|
stashedStatus.textContent = '⚠️ ' + errorMsg;
|
||||||
|
|
||||||
|
// If it was a NotSupportedError (likely empty buffer), we can try to recover automatically
|
||||||
|
// by waiting for data and trying to play again (even if it might fail without gesture)
|
||||||
|
if (error.name === 'NotSupportedError') {
|
||||||
|
console.log('🔄 Retrying playback in background once data arrives...');
|
||||||
|
const retryInterval = setInterval(() => {
|
||||||
|
if (window.listenerAudio.buffered && window.listenerAudio.buffered.length > 0) {
|
||||||
|
clearInterval(retryInterval);
|
||||||
|
window.listenerAudio.play().catch(e => console.error('Background retry failed:', e));
|
||||||
|
stashedStatus.textContent = '🟢 Recovered - Playing';
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user