Reputation: 11
let's imagine if i'm building a music player okay ? actually i did it but i faced a problem when i try to get list of the songs and get their duration i must create audio element for each song and it waste alot of data so there's in a pure js code or another without writing duration statically ? this is my code
songs.map((song) => {
if(!song.hasOwnProperty("duration")){
let aud = new Audio();
aud.src = `audios/${song.audioName}.mp3`
aud.addEventListener('loadedmetadata',() => {
let durationAud = aud.duration;
song.duration = durationAud;
})
}
})
}
Upvotes: 0
Views: 978
Reputation: 691
You would solve this creating a row in a database with your audio file's metadata. Then, you would request that data on your frontend with an AJAX call.
Upvotes: 2