I'm trying to play audio using React when a button is clicked, but i get this error when i do it "Uncaught (in promise) DOMException: Failed to load because no supported source was found."
here's the code:
function playAudio() {
const audio = new Audio("./audios/song.mp3");
audio.play();
}
<button onClick={playAudio}>PLAY</button>
The only solution i've found is to import the audio, but i can't find a way of doing it in a flexible way since i need to use a lot of audios, and importing manually 20 audios doesn't seem the best way of doing it. Anyone knows a solution?