diff --git a/public/app.js b/public/app.js index d047648..fc1f3c0 100644 --- a/public/app.js +++ b/public/app.js @@ -299,6 +299,14 @@ async function ensureYoutubePlayer() { return youtubePlayer; } +function requestYoutubePlayback(player) { + for (const delay of [0, 150, 750, 1500, 3000]) { + setTimeout(() => { + if (desiredYoutubePlaying) player.playVideo(); + }, delay); + } +} + async function sendWatchState({ videoId = currentYoutubeVideoId, position = 0, @@ -406,7 +414,9 @@ async function applyWatchState(state, { suppressEvents = true } = {}) { if (suppressEvents) { applyingWatchStateUntil = Date.now() + 3000; } - if (!shouldPlay) { + if (shouldPlay) { + pauseEnforcementUntil = 0; + } else { pauseEnforcementUntil = Math.max(pauseEnforcementUntil, Date.now() + 3000); } @@ -422,10 +432,7 @@ async function applyWatchState(state, { suppressEvents = true } = {}) { } else { player.loadVideoById(currentYoutubeVideoId, position); } - player.playVideo(); - setTimeout(() => { - player.playVideo(); - }, 150); + requestYoutubePlayback(player); } else { if (player.getVideoData?.().video_id !== currentYoutubeVideoId) { player.cueVideoById(currentYoutubeVideoId, position);