是否有可能获得mp3的比特率? [英] Is it possible to get bitrate of mp3?
本文介绍了是否有可能获得mp3的比特率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Chrome扩展程序显示了指向 .mp3
文件的链接的列表,我需要获取每个元素的比特率.我该如何计算?
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?
更新
解决了.
推荐答案
通过以下简单的AJAX请求解决了该问题:
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.
这篇关于是否有可能获得mp3的比特率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文