I have a countdown timer that plays a sound when it finishes, and I would like the sound to not pause/interfere with existing audio that is playing on the user's device via another app (like Spotify). On a computer (Macbook Pro), this works across browsers and the alarm sound plays over background music. On a mobile phone (iPhone) background music is paused when the countdown is finished and alarm plays and am required to replay background audio. I don't have the knowledge to come up with a workaround for this and any help is really appreciated! I modified the code below from this post which helped solve the barrier to autoplay initially:
const audio = new Audio("https://www.fesliyanstudios.com/play-mp3/4385");
let time = ${time};
btn.onclick = e => {
// mark our audio element as approved by the user
audio.load();
countdown();
btn.disabled = true;
};
function countdown() {
document.getElementById("pre").style.color ="#12A89E";
document.getElementById("pre").innerHTML = --time + "s work time";
if(time === 0) return onend();
setTimeout(countdown, 1000);
}
function onend() {
audio.play(); // now we're safe to play it
document.getElementById("pre").style.color ="#A81248";
document.getElementById("pre").innerHTML = "NEXT MOVEMENT";
time = ${time}
btn.disabled = false;
}