How do I make it so that when audio is uploaded it can be played? I used this code, but it didn\'t work.
function handleFiles(event) {
var files = event.target.files;
$("#audio").attr("src", URL.createObjectURL(files[0]));
$("#player")[0].load();
$("#player")[0].play();
}
document.getElementById("file").addEventListener("change", handleFiles, false);
This is pretty much the same thing as the most upvoted answer by @Kaiido, but uses Jquery. Furthermore, you have to use .load();
to load the audio before you play it. So what this code does for you is you can upload any audio file, and it will automatically start playing. Thanks!