- Joined
- Dec 14, 2021
- Messages
- 28
- Reaction score
- 2
I have this code I need help making the
Here is the file selector, on the HTML file:
Also, you don't need
Make sure to give me the context of your answer.
audio.duration
work. Here's the code:
JavaScript:
function addTrack(tkFile) {
var trackSource = URL.createObjectURL(tkFile.files[0]);
var trackLth;
var trackName = tkFile.files[0].name;
const div = document.createElement("div");
div.className = "track";
const audio = document.createElement("audio");
var reader = new FileReader();
reader.onload = function (e) {
audio.controls = true;
audio.src = trackSource;
audio.innerHTML = "Your browser does not support the audio element.";
audio.onloadedmetadata = function() {
trackLth = getHHMMSSFromSeconds(parseInt(audio.duration));
};
}
reader.readAsDataURL(tkFile.files[0]);
div.appendChild(audio);
//There's more here but it all is just adding stuff to the HTML, not important to the audio creation
}
Here is the file selector, on the HTML file:
HTML:
<label for="trackFile">Select a file: (Only Audio Files)</label>
<input type="file" id="trackFile" name="trackFile" onchange="addTrack(this)" accept="audio/*">
Also, you don't need
getHHMMSSFromSeconds()
, as all it does is format seconds into a HH:MM:SS format.Make sure to give me the context of your answer.