Open jester6san opened 3 years ago
I've noticed the same thing. On iOS Safari the device falls asleep after being backgrounded and foregrounded even though when I drag down from the top of the iPhone to see that menu I can see the video playing on a loop. I've also noticed that when the device is charging this isn't an issue, but when the device is not charging then backgrounding and then foregrounding does not work.
What I've found is that after a tab becomes hidden and then visible again (as can be determined by the PageVisibility API), you need to capture a new user interaction to play the hidden background video to prevent the device from falling asleep.
Hey I tried that, but it fails to resume or re-initialize the plugin. I've only tested this on iPhone since that's the main platform that's going to run my project...
Try this code:
var btnNoSleep = document.createElement('button');
btnNoSleep.onclick = function() { if (noSleep.isEnabled()) { noSleep.disable(); }
noSleep.enable();
};
document.addEventListener('visibilitychange', function() { if (document.visibilityState == "visible") { btnNoSleep.click(); } });
Apparently it works for me on Safari IOS 14.7.1
Tested on iOS 14.5.1, Google Chrome and Safari. I've tried enabling and disabling, initialising it again using window.onblur and window.onfocus events. Are there any solutions for this?