I can't find how to play an audio file that the user has just selected with an input. I have the following input :
<input type='file' id="audio-input" class="audio-input" name="audio" accept=".mp3, .wav"/>
I would like display the audio file when the user select it so he can play it. It would be something like that :
('#audio-input-0').change( function () {
let audio =
"<audio controls>" +
" <source id='audioFile' type='audio/mpeg'>" +
" Your browser does not support the audio element." +
"</audio>";
$('body').append(audio);
$('#audioFile').attr('src', $(this).val());
});
I hope you understand what I'm trying to do, I don't really know how to explain it (maybe that's why I don't find any answers on other topics).
how to play audio file with fileReader. I belive this is what you need but in terms of audio (same thing, reading as url and pasting to src): developer.mozilla.org/en-US/docs/Web/API/FileReader/…