I’ve got a bit of Javascript to play an audion on clicking an element:
const btn1 = document.querySelectorAll(".btn-sound-1");
let audio1 = new Audio('https://nullsieben.co.uk/74.mp3');
btn1.forEach(btn => {
btn.addEventListener("click", () => {
audio1.play();
});
});
https://jsfiddle.net/wjq0ydhz/
I’d like to add the following:
- Delay from clicking the button until the mp3 starts paying
- Is there a way with this code to pre-load the sound so that it definately will when it’s supposed to, regardless of bandwidth etc.?