JSFiddle - React, Tailwind, and code Playground

by Kishore Sahasranaman

HTML

<input id="testurl" type="text"></input> <input type="button" id="getduration" value="get duration"></input>
<div id="result"></div>Try copying this link to the above text box : https://ia802508.us.archive.org/5/items/testmp3testfile/mpthreetest.mp3

JavaScript

$("#getduration").on("click", function (e) {
    loadMusic($("#testurl").val());
});
var ctx = new AudioContext();

function loadMusic(url) {
    var req = new XMLHttpRequest();
    $("#result").html("Please wait .. "); // 116
    req.open('GET', url, true);
    req.responseType = 'arraybuffer';
    req.onload = function () {
        ctx.decodeAudioData(req.response, function (buffer) {
            $("#result").html("Duration :" + buffer.duration); // 116
        })
    };
    req.send();
}