p5.js-sound
p5.js-sound copied to clipboard
iOS 15, sound stop playing if Safari minimized or screen is locked.
On iOS 15 if you go for example to this example https://p5js.org/reference/#/p5.SoundLoop start playing audio and then minimize safari or lock the screen the audio "mutes" and continue laying one you unlock the screen or make safari active again. attaching a short video demo from the iOS 15 simulator, the similar thing on the actual phone.
html5 audio works with no problem, it keeps playing if I lock the screen.
https://user-images.githubusercontent.com/31907796/137606074-fd7902c3-3036-41a8-9a3d-4bddd0ef2ce3.mov
I submitted it to Apple feedback (bug report) https://feedbackassistant.apple.com/feedback/9709046 But I am not sure if that is a bug or some "new feature" of the apple. If you know some workaround, please share. Thank you!
this seems to fix it:
//first make sure AudioContext is loaded, then set the state change
var checkAudContextInterval = setInterval(function(){
if(typeof getAudioContext !== 'undefined'){
getAudioContext().onstatechange = function() {
// console.log(getAudioContext().state);
if (getAudioContext().state === 'suspended' || getAudioContext().state === 'interrupted') {
getAudioContext().resume();
}
};
clearInterval(checkAudContextInterval);
}
}, 1000);
This might help
https://github.com/swevans/unmute
var setPhoneUnmute = false;
function touchStarted() {
if (setPhoneUnmute == false && getAudioContext.state !== 'running') {
setPhoneUnmute = true;
unmute(getAudioContext());
}
}