From 2a092577c69d41c06f8f094348c2dd88fc6b1a17 Mon Sep 17 00:00:00 2001 From: Ming Kin Choi Date: Sun, 27 Aug 2023 12:50:36 +0800 Subject: [PATCH 1/2] Fix iOS screen timeout on video playback loop mode --- assets/js/player.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/assets/js/player.js b/assets/js/player.js index bb53ac24..0c37033d 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -701,6 +701,21 @@ if (navigator.vendor === 'Apple Computer, Inc.' && video_data.params.listen) { }); } +// Safari screen timeout on looped video playback fix +if (navigator.vendor === 'Apple Computer, Inc.' && !video_data.params.listen && video_data.params.video_loop) { + player.loop(false); + player.on('loadedmetadata', function () { + player.on('timeupdate', function () { + if (player.remainingTime() < 2) { + player.loop(true); + setTimeout(() => { + player.loop(false); + }, 2000 / player.playbackRate()); + } + }); + }); +} + // Watch on Invidious link if (location.pathname.startsWith('/embed/')) { const Button = videojs.getComponent('Button'); From 27d8fa112dad0b531d4e3f24045975a1869ab2ff Mon Sep 17 00:00:00 2001 From: Ming Kin Choi Date: Sun, 27 Aug 2023 14:11:45 +0800 Subject: [PATCH 2/2] Fix iOS screen timeout on video playback loop mode (more elegantly) --- assets/js/player.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/assets/js/player.js b/assets/js/player.js index 0c37033d..5d88d069 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -704,14 +704,10 @@ if (navigator.vendor === 'Apple Computer, Inc.' && video_data.params.listen) { // Safari screen timeout on looped video playback fix if (navigator.vendor === 'Apple Computer, Inc.' && !video_data.params.listen && video_data.params.video_loop) { player.loop(false); - player.on('loadedmetadata', function () { - player.on('timeupdate', function () { - if (player.remainingTime() < 2) { - player.loop(true); - setTimeout(() => { - player.loop(false); - }, 2000 / player.playbackRate()); - } + player.ready(function () { + player.on('ended', function () { + player.currentTime(0); + player.play(); }); }); }