Writing a 16bit bytearray in as3
I'm trying to write the following 16bit WAV header data into a 16bit bytearray. Does anyone know how to achie开发者_开发知识库ve this? I am using actionscript 3.
52 49 46 46 54 00 13 00 57 41 56 45 62 65 78 74 5A 02
What I'm doing is trying to pass the correct bytearray to this mp3 encoder (http://code.google.com/p/flash-kikko/) to get it to write out an mp3. If I use their example, I can open a 16bit WAV file via filereference and pass in that bytearray to the encoder to export an mp3. But, I want to create my own bytearray and pass it in and create the mp3. Using HxD, I copied the header and footer of that same 16bit WAV file and pasted it into flash as a bytearray, but when I pass it into the encoder, it freezes the compile and I get the following error:
Error #1502: A script has executed for longer than the default timeout period of 15 seconds.
So, I think my issue is with how I'm formatting the bytearray that I'm passing in... any ideas? Thanks again for the help!
I assume you want all 18 bytes (your question says 16 bits)?
var byteArray:ByteArray = new ByteArray();
byteArray.writeByte(0x52);
byteArray.writeByte(0x49);
byteArray.writeByte(0x46);
etc. Just follow the pattern for the remaining 15 bytes.
Each of the two digits you show, for example, "5A" actually represents a byte in hexadecimal. The 0x is needed to tell Flash you're using hex values -- otherwise, AS3 will think you're using decimal.
Why not automate tedious job...
var header:String = "52 49 46 46 54 00 13 00 57 41 56 45 62 65 78 74 5A 02";
var headerParts:Array = header.split(" ");
var bytes:ByteArray = new ByteArray();
for each (var s:String in headerParts)
{
bytes.writeByte(parseInt(s, 16));
}
Now bytes contains your header.
精彩评论