The following code is a FFish script clone of the c++ code from the site. you can write your own id3 tag reader.
We found a design fault of the Stream object. It's only designed to access small text files, requires both reading and writing permission. It cannot handle read-only files. However, the fault is fixed. The following code can't work on read-only files before the new update come out.
Code:
function mp3Header(head)
{
this.frameHeader = head;
this.getVersion = function ()
{
var version = [2.5, 0.0, 2.0, 1.0];
return version[this.getVersionIndex()];
}
this.getLayer = function ()
{
return 4 - this.getLayerIndex();
}
this.getBitrate = function ()
{
var table = [0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0,
0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0,
0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0,
0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0,
0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0,
0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0];
var index = 48 * (this.getVersionIndex() & 1) + 16 * (this.getLayerIndex() - 1) + this.getBitrateIndex();
return table[index];
}
this.getFrequency = function ()
{
var table = [32000, 16000, 8000, 0, 0, 0, 22050, 24000, 16000, 44100, 48000, 32000];
var index = this.getVersionIndex() * 3 + this.getFrequencyIndex();
return table[index];
}
this.getMode = function ()
{
switch (this.getModeIndex())
{
case 1: return "Joint Stereo";
case 2: return "Dual Channel";
case 3: return "Single Channel";
default: return "Stereo";
}
}
this.isValid = function ()
{
return (((this.getFrameSync() & 2047) == 2047) &&
((this.getVersionIndex() & 3) != 1) &&
((this.getLayerIndex() & 3) != 0) &&
((this.getBitrateIndex() & 15) != 0) &&
((this.getBitrateIndex() & 15) != 15) &&
((this.getFrequencyIndex() & 3) != 3) &&
((this.getEmphasisIndex() & 3) != 2));
}
function getFrameSync() { return ((this.frameHeader >> 21) & 2047); };
function getVersionIndex() { return ((this.frameHeader >> 19) & 3); };
function getLayerIndex() { return ((this.frameHeader >> 17) & 3); };
function getProtectionBit() { return ((this.frameHeader >> 16) & 1); };
function getBitrateIndex() { return ((this.frameHeader >> 12) & 15); };
function getFrequencyIndex(){ return ((this.frameHeader >> 10) & 3); };
function getPaddingBit() { return ((this.frameHeader >> 9) & 1); };
function getPrivateBit() { return ((this.frameHeader >> 8) & 1); };
function getModeIndex() { return ((this.frameHeader >> 6) & 3); };
function getModeExtIndex() { return ((this.frameHeader >> 4) & 3); };
function getCoprightBit() { return ((this.frameHeader >> 3) & 1); };
function getOrginalBit() { return ((this.frameHeader >> 2) & 1); };
function getEmphasisIndex() { return ((this.frameHeader) & 3); };
}
function getMP3Header(name)
{
var stream = new Stream(name);
var mp3HeadInfo = new mp3Header(0);
var head = 0;
do
{
if (stream.pos > 200 || stream.pos >= stream.length)
{
stream.close();
return null;
}
var s = stream.read(4);
mp3HeadInfo.frameHeader = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
processMsg();
}
while (!mp3HeadInfo.isValid());
stream.close();
if (mp3HeadInfo.isValid()) return mp3HeadInfo;
return null;
}
var info = getMP3Header("c:\\songs\\1.mp3");
if (info)
{
trace(info.getVersion());
trace(info.getLayer());
trace(info.getBitrate());
trace(info.getFrequency());
trace(info.getMode());
}