国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > WEB開發 > 正文

8.15.讀取mp3文件的ID3數據

2024-04-27 13:52:05
字體:
來源:轉載
供稿:網友
8.15.1. 問題
我需要從一個MP3 文件中讀取ID3 數據。
8.15.2. 解決辦法
使用Event.ID3 方法,當ID3 數據被分析時Sound 類將被迅速處理
8.15.3. 討論
當把一個裝載的MP3 文件的ID3 數據被分析時,Sound 類迅速處理一個事件。這些數據被作為一個ID3Info 對象保存,它定義的變量訪問的所有屬性被寫入MP3 開頭的字節中:
+展開
-ActionScript
private var sound:Sound;
public function _8_16()
{
sound = new Sound();
sound.addEventListener(Event.ID3, onID3InfoReceived);
sound.load(new URLRequest("../assets/1.mp3"));
}
private function onID3InfoReceived(event:Event):void
{
var id3:ID3Info = event.target.id3;
for (var propName:String in id3)
{
trace(propName + " = " + id3[propName]);
}
}

一首我聽的歌中的信息,我寫的這方似乎是這樣的:
TCON = Alternative & Punk
TIT2 = The Pink Batman
TRCK = 2/9
TPE1 = Dan Deacon
TALB = Spiderman Of The Rings
TCOM = Dan Deacon

MP3 文件的ID3 信息是一個簡單的按一定次序分組的字節,讀取和返回字符串或整數。MP3是Flash Player 支持的唯一一種格式。RichApps (www.richapps.de)的開發者Benjamin Dobler,不管怎么樣,已經為WAV 格式作了一些優秀的工作。得到WAV 文件在Flash Player中播放稍微困難一些。如果你有興趣,可以到Benjamin 的網站去看看。如果你需要從WAV文件中分析數據,看起來像這樣:
+展開
-ActionScript
public var bytes:ByteArray;
public var chunkId:String;
public var chunkSize:int;
public var chunkFormat:String;
public var subchunk1Id:String;
public var subchunk1Size;
public var audioFormat;
public var channels;
public var sampleRate;
public var bytesPersecond;
public var blockAlign;
public var bitsPerSample;
public var dataChunkSignature:String;
public var dataChunkLength;
public function read(bytes:ByteArray):void{
this.bytes = bytes;
// Read Header
bytes.endian = "littleEndian";
chunkId = bytes.readMultiByte(4,"utf"); //RIFF
chunkSize = bytes.readUnsignedInt();
chunkFormat = bytes.readMultiByte(4,"utf"); //WAVE
subchunk1Id = bytes.readMultiByte(4,"iso-8859-1"); // 12Header Signature
subchunk1Size = bytes.readInt(); // 16 4 <fmt length>
audioFormat = bytes.readShort(); // 20 2 <format tag> sample
channels = bytes.readShort(); // 22 2 <channels> 1 = mono,2 = stereo
sampleRate = bytes.readUnsignedInt();// 24 4 <sample rate>
bytesPersecond = bytes.readUnsignedInt(); //28 4<bytes/second> Sample-Rate * Block-Align
blockAlign = bytes.readShort(); // 32 2 <block align> channel * bits/sample / 8
bitsPerSample = bytes.readUnsignedShort(); //34 2<bits/sample> 8, 16 or 24
dataChunkSignature = bytes.readMultiByte(4,"iso-8859-1");
//RIFF
dataChunkLength = bytes.readInt();
}

如果你需要從AU 文件讀取頭信息,那看起來像這樣:
+展開
-ActionScript
public var bytes:ByteArray;
public var magicId;
public var header;
public var datasize;
public var channels;
public var comment;
public var sampleRate;
public var encodingInfo;
public function read(bytes:ByteArray):void{
this.bytes = bytes;
// Read Header
bytes.endian = "bigEndian";
magicId = bytes.readUnsignedInt();
header = bytes.readInt();
datasize = bytes.readUnsignedInt();
encodingInfo = bytes.readUnsignedInt();
sampleRate = bytes.readUnsignedInt();
channels = bytes.readInt();
comment = bytes.readMultiByte(uint(header)-24, "utf");
}

MP3 可能是讀取數據最簡單的格式,但是他們無疑不是我們能讀取得唯一格式。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 商南县| 唐海县| 双城市| 海晏县| 眉山市| 通山县| 枣强县| 海淀区| 龙里县| 乡宁县| 壤塘县| 仁化县| 尼勒克县| 扎兰屯市| 巢湖市| 盐边县| 西吉县| 钟祥市| 桐庐县| 彰化县| 资源县| 普陀区| 醴陵市| 文山县| 江西省| 仲巴县| 襄汾县| 中西区| 虹口区| 连山| 自贡市| 镇赉县| 清原| 芦溪县| 岗巴县| 房产| 阿拉善右旗| 义乌市| 雷州市| 瑞昌市| 北宁市|