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) <noreply@anthropic.com>
This commit is contained in:
ScreenTinker 2026-04-28 16:18:32 -05:00
parent a3551a2654
commit b2aa7fab54
2 changed files with 13 additions and 5 deletions

View file

@ -139,16 +139,24 @@
['click', 'touchstart', 'keydown'].forEach(evt => { ['click', 'touchstart', 'keydown'].forEach(evt => {
document.addEventListener(evt, () => { document.addEventListener(evt, () => {
userHasInteracted = true; 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'); const video = document.querySelector('#playerContainer video');
if (video && video.muted) { if (video && video.muted) {
video.muted = false; video.muted = false;
video.play().catch(() => {}); video.play()
console.log('Unmuted video after user interaction'); .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 // Unmute YouTube player if active
if (activeYtPlayer && typeof activeYtPlayer.unMute === 'function') { 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 }); }, { once: false });
}); });

View file

@ -1,4 +1,4 @@
const CACHE_NAME = 'rd-player-v8'; const CACHE_NAME = 'rd-player-v9';
// Install: skip waiting to activate immediately // Install: skip waiting to activate immediately
self.addEventListener('install', (event) => { self.addEventListener('install', (event) => {