From b29e504bb33e80203c91e2613c16852886b94e0f Mon Sep 17 00:00:00 2001 From: Glenn Thompson Date: Fri, 12 Dec 2025 18:31:58 +0300 Subject: [PATCH] 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 --- parenscript/front-page.lisp | 11 +++++++++++ template/audio-player-frame.ctml | 13 +++++++++++++ template/popout-player.ctml | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/parenscript/front-page.lisp b/parenscript/front-page.lisp index 6a15c26..a262789 100644 --- a/parenscript/front-page.lisp +++ b/parenscript/front-page.lisp @@ -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" diff --git a/template/audio-player-frame.ctml b/template/audio-player-frame.ctml index 0d72fa1..522ab7b 100644 --- a/template/audio-player-frame.ctml +++ b/template/audio-player-frame.ctml @@ -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 diff --git a/template/popout-player.ctml b/template/popout-player.ctml index c22b7a6..735f15c 100644 --- a/template/popout-player.ctml +++ b/template/popout-player.ctml @@ -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' }, '*');