0
I’m trying to implement a music player using javascript, which works by uploading an audio file (.mp3), in the script when the file is uploaded, which occurs with the 'onload' event the function created has the variable 'files' and then play the file. How the file is played if it apparently does not reference the variable that receives the file 'file'?
HTML
<div id="content">
<input type="file" id="thefile" accept="audio/*" />
<audio id="audio" controls="controls"></audio>
</div>
Javascript
window.onload = function() {
var file = document.getElementById("thefile");
var audio = document.getElementById("audio");
file.onchange = function() {
var files = this.files;
audio.src = URL.createObjectURL(files[0]);
audio.load();
audio.play();
}
};
Grateful from now on.
thanks for the explanation, helped mto, but my doubt persists in the part of the role played by the variable
files
.– jaojpaulo
I edited the answer with the explanation of
files
– Dobrychtop