-1

My Chrome extension shows a list of links to .mp3 files and I need to get the bitrate for each element. How can I calculate this?

UPDATE

Solved it.

Glebcha
  • 161
  • 2
  • 14
  • but there is no answer. – Glebcha Feb 07 '14 at 17:34
  • There's no "copy/pasta" answer, but there's a nice research that should get you started. Note that showing your research efforts is essential when asking here (avoids down and close votes, see [ask]). I bet you'll end up finding a solution and posting the code in that duplicate ;) Good luck. – brasofilo Feb 07 '14 at 17:57

1 Answers1

10

Solved it with this simple AJAX request:

var audioLink = document.querySelector('.my_audio_link_class');
var durationBlock = document.querySelector('.element_with_duration_in_text_class').innerText.split(':'); //it has string '1:36' for example and i create new array with minutes and seconds
var duration = durationBlock[0]*60 + +durationBlock[1]; //convert minutes into seconds and convert string with second into integer, then summarize them

function (audioLink, duration) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.overrideMimeType('text/xml');

xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        var size = xmlhttp.getResponseHeader('Content-Length');//get file size
        var kbit=size/128;//calculate bytes to kbit
    var kbps= Math.ceil(Math.round(kbit/duration)/16)*16;
    console.log(kbps);
    }
};
xmlhttp.open("HEAD", audioLink, true);
xmlhttp.send();
}

Hope it helps someone and sorry for my bad english.

Glebcha
  • 161
  • 2
  • 14