Add pause event handler for muted stream throttling

- Detect when browser pauses muted stream (throttling)
- Auto-reconnect after 3 seconds when paused while muted
- Apply to all three players for consistency
This commit is contained in:
Glenn Thompson 2025-12-12 18:31:58 +03:00 committed by Brian O'Reilly
parent 2cd128260c
commit b29e504bb3
3 changed files with 36 additions and 0 deletions

View File

@ -355,6 +355,17 @@
(setf *is-reconnecting* t)
(set-timeout reconnect-stream 2000))))
;; Pause handler - detect browser throttling muted streams
(ps:chain audio-element
(add-event-listener "pause"
(lambda ()
(when (and (ps:@ audio-element muted)
(not *is-reconnecting*))
(ps:chain console (log "Stream paused while muted (possible browser throttling), reconnecting..."))
(show-stream-status "⚠️ Stream paused - reconnecting..." "warning")
(setf *is-reconnecting* t)
(set-timeout reconnect-stream 3000)))))
;; Waiting handler (buffering)
(ps:chain audio-element
(add-event-listener "waiting"

View File

@ -300,6 +300,19 @@
reconnectStream();
}, 2000);
});
// Handle pause event - detect browser throttling muted streams
audioElement.addEventListener('pause', function() {
// If paused while muted and we didn't initiate it, browser may have throttled
if (audioElement.muted && !isReconnecting) {
console.log('Stream paused while muted (possible browser throttling), will reconnect in 3 seconds...');
showStatus('⚠️ Stream paused - reconnecting...', true);
isReconnecting = true;
setTimeout(function() {
reconnectStream();
}, 3000);
}
});
}
// Attach listeners to initial audio element

View File

@ -178,6 +178,18 @@
}, 2000);
});
// Handle pause event - detect browser throttling muted streams
audioElement.addEventListener('pause', function() {
if (audioElement.muted && !isReconnecting) {
console.log('Stream paused while muted (possible browser throttling), reconnecting...');
isReconnecting = true;
setTimeout(function() {
audioElement.load();
audioElement.play().catch(err => console.log('Reconnect failed:', err));
}, 3000);
}
});
// Notify parent window that popout is open
if (window.opener && !window.opener.closed) {
window.opener.postMessage({ type: 'popout-opened' }, '*');