Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private var buf:ByteArray = new ByteArray();
- private var sbuf:ByteArray = new ByteArray();
- protected function voiceReceive(event:ProgressEvent):void
- {
- var avail:uint = VoiceSock.bytesAvailable;
- trace("voice received "+avail+".");
- if (avail > 0) {
- // get bytes from socket, write to buffer
- VoiceSock.readBytes(sbuf); // buffer socket data
- // reset position
- sbuf.position = 0;
- // get ID
- var _id:ByteArray = new ByteArray();
- _id.writeBytes(sbuf, 0, 4);
- _id.position = 0;
- var id:int = _id.readInt();
- // get data LEN
- var _len:ByteArray = new ByteArray();
- _len.writeBytes(sbuf, 4, 4);
- _len.position = 0;
- var len:int = _len.readInt();
- if (id < 0 || len < 0)
- return;
- // check/create new user control
- if (!sounds.containsKey(id)) {
- sounds.put(id, new SoundObj());
- }
- if (sbuf.length >= 8+len) {
- // read data
- var buf:ByteArray = new ByteArray();
- buf.writeBytes(sbuf, 8, len);
- // crop used data
- var _buf:ByteArray = new ByteArray();
- _buf.writeBytes(sbuf, 8+len, sbuf.length-(8+len));
- sbuf = _buf;
- // write all but ID bytes to specialized buffer
- sounds.get(id).receive(buf);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment