Is it possible to get bitrate of mp3? [duplicate]

笑着哭i 提交于 2021-02-07 11:11:46

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/21634091/is-it-possible-to-get-bitrate-of-mp3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!