The following code plays the audio correctly on Chrome 88, but on Firefox 85 the audio cuts off and sometimes doesn't even play.
window.onload = function() {
Audio.prototype.stop = function() {
audio.pause();
audio.currentTime = 0;
}
let audio = new Audio("./audio.mp3");
let count = 0;
function replay() {
audio.stop();
audio.play();
}
let button = document.getElementsByTagName("button")[0];
button.addEventListener("click", function() {
let interval = setInterval(function() {
if (count < 10) {
replay();
count += 1;
} else {
clearInterval(interval);
count = 0;
}
}, 100);
});
}
How can I fix this so that audio is played correctly in Firefox? All the files needed to reproduce the problem can be found here.