Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.events.*;
- import flash.external.*;
- import flash.media.Sound;
- import flash.net.URLRequest;
- Security.allowDomain('*');
- ExternalInterface.addCallback('proxySound', this.proxySound);
- var sound:Sound = new Sound();
- sound.addEventListener(ProgressEvent.PROGRESS, process);
- sound.addEventListener(IOErrorEvent.IO_ERROR, error);
- function proxySound(url:String):void {
- var urlReq:URLRequest = new URLRequest(url);
- sound.load(urlReq);
- }
- function process(event:Event) {
- var bytes:ByteArray = new ByteArray();
- while (sound.extract(bytes, 40960)) {
- bytes.position = 0;
- var samples:Array = new Array(bytes.length);
- for (var i:int = 0, n:int = bytes.length / 4; i < n; ++i)
- samples[i] = bytes.readFloat();
- ExternalInterface.call('samples', samples);
- }
- }
- function error(event:Event):void {
- ExternalInterface.call('error');
- }
Add Comment
Please, Sign In to add comment