how to get audio.duration value by a function : <p>Im my audio player I need to get the duration of my audio track. I need a function that gets src of the audio and returns its duration. Here is what I am trying to do but does not work:</p>

<pre><code>function getDuration(src){
    var audio = new Audio();
    audio.src = "./audio/2.mp3";
    var due;
    return getVal(audio);
}
function getVal(audio){
    $(audio).on("loadedmetadata", function(){
        var val = audio.duration;
        console.log("&gt;&gt;&gt;" + val);
        return val;
    });
}
</code></pre>

<p>I tried to split into two functions but it does not work. It would be great if it was as on working function.</p>

<p>Any idea?</p>
