Skip to content
Advertisement

How to get audio.duration from a player and save it to a div on a click?

I’ve been looking for a way to get the duration of a MP3 file that’s hosted remotely and I found answer from another question (How can I get the html5 audio’s duration time) and now I’m trying to see if I make it work.

I’m hung up this part:

JavaScript

What that code does is getting the duration of a MP3 file and display it in the console. What I’m trying to do get the duration of the MP3 file when you click on a button and save that data into a ”.

Here’s my code so far:

JavaScript
JavaScript
JavaScript

Advertisement

Answer

JavaScript
JavaScript

I did this and it worked.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement