Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 audio tag Duration

How come each time I call the

var track_length = $(".audio-player")[counter].duration;

it returns me this

351.234

How can I convert it to this type ofr Format minutes/seconds. 3:51 seconds ?(I am not sure if I am correct with my estimation of the time)

like image 709
user962206 Avatar asked Dec 21 '22 17:12

user962206


1 Answers

Do you mean you want to convert it to min and secs, if yes then:

function readableDuration(seconds) {
    sec = Math.floor( seconds );    
    min = Math.floor( sec / 60 );
    min = min >= 10 ? min : '0' + min;    
    sec = Math.floor( sec % 60 );
    sec = sec >= 10 ? sec : '0' + sec;    
    return min + ':' + sec;
}
console.log( readableDuration(351.234) ); // 05:51
like image 50
Sudhir Bastakoti Avatar answered Dec 28 '22 08:12

Sudhir Bastakoti