mirror of
https://github.com/screentinker/screentinker.git
synced 2026-05-15 07:32:23 -06:00
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:
parent
a3551a2654
commit
b2aa7fab54
|
|
@ -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 });
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue