i try to play an audio in mp3 format with JavaScript but it is dosen't work, I get the following problem: Uncaught (in promise) DOMException: The element has no supported sources.
https://codepen.io/matiasConchaSoto/pen/KKqeWwg
const d = document;
export function alarm(sound, btnPlay, btnStop) {
let alarmTempo;
const $alarm = d.createElement("audio");
$alarm.src = sound;
d.addEventListener("click", e => {
if(e.target.matches(btnPlay)){
alarmTempo = setTimeout(() => {
$alarm.play();
}, 2000);
e.target.disabled = true;
}
if(e.target.matches(btnStop)){
clearTimeout(alarmTempo);
$alarm.pause();
$alarm.currentTime = 0;
d.querySelector(btnPlay).disabled = false;
}
});
}
My code is even bigger and i have a document js index where i imported all my function, but this is the part of the problem, in the function alarm(sound, btnPlay, btnStop), sound is a mp3 audio, btnPlay is a button with the id="activar-alarma" and btnStop is a button with the id="desactivar-alarma", a little help please :C.