From b2aa7fab549bc20388b728d6e30392485444a9c1 Mon Sep 17 00:00:00 2001 From: ScreenTinker Date: Tue, 28 Apr 2026 16:18:32 -0500 Subject: [PATCH] Player: keep video playing if unmute is blocked video.play().catch(() => {}) silently swallowed the rejection from the browser's autoplay policy, so when a user click triggered the unmute path the video paused (browser side-effect of unmuting a muted-autoplay video) and never resumed. Surface the play() rejection in the log, and fall back to muted playback if the unmuted play() is blocked. Same for the YT side: explicitly set volume on unmute. Bumped SW cache to v9. Co-Authored-By: Claude Opus 4.7 (1M context) --- server/player/index.html | 16 ++++++++++++---- server/player/sw.js | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server/player/index.html b/server/player/index.html index 64b00ee..4c3f50b 100644 --- a/server/player/index.html +++ b/server/player/index.html @@ -139,16 +139,24 @@ ['click', 'touchstart', 'keydown'].forEach(evt => { document.addEventListener(evt, () => { userHasInteracted = true; - // Try to unmute any playing HTML5 video + // HTML5 video: setting muted=false on a video that's been muted-autoplaying + // causes the browser to pause it as a side effect. We have a real user + // gesture here, so play() should succeed — but if it doesn't, fall back to + // muted playback rather than leaving a black/paused screen. const video = document.querySelector('#playerContainer video'); if (video && video.muted) { video.muted = false; - video.play().catch(() => {}); - console.log('Unmuted video after user interaction'); + video.play() + .then(() => console.log('Unmuted video after user interaction')) + .catch(err => { + console.warn('Unmuted play() rejected, falling back to muted:', err?.message || err); + video.muted = true; + video.play().catch(e => console.warn('Muted fallback play() failed:', e?.message || e)); + }); } // Unmute YouTube player if active if (activeYtPlayer && typeof activeYtPlayer.unMute === 'function') { - try { activeYtPlayer.unMute(); console.log('Unmuted YouTube player'); } catch {} + try { activeYtPlayer.unMute(); activeYtPlayer.setVolume(100); console.log('Unmuted YouTube player'); } catch {} } }, { once: false }); }); diff --git a/server/player/sw.js b/server/player/sw.js index 8f841b7..f4899d6 100644 --- a/server/player/sw.js +++ b/server/player/sw.js @@ -1,4 +1,4 @@ -const CACHE_NAME = 'rd-player-v8'; +const CACHE_NAME = 'rd-player-v9'; // Install: skip waiting to activate immediately self.addEventListener('install', (event) => {