Guest User

Untitled

a guest
Jul 8th, 2018
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import flash.events.*;
  2. import flash.external.*;
  3. import flash.media.Sound;
  4. import flash.net.URLRequest;
  5.  
  6. Security.allowDomain('*');
  7.  
  8. ExternalInterface.addCallback('proxySound', this.proxySound);
  9.  
  10. var sound:Sound = new Sound();
  11. sound.addEventListener(ProgressEvent.PROGRESS, process);
  12. sound.addEventListener(IOErrorEvent.IO_ERROR, error);
  13.  
  14. function proxySound(url:String):void {
  15.   var urlReq:URLRequest = new URLRequest(url);
  16.   sound.load(urlReq);
  17. }
  18. function process(event:Event) {
  19.   var bytes:ByteArray = new ByteArray();
  20.   while (sound.extract(bytes, 40960)) {
  21.     bytes.position = 0;
  22.     var samples:Array = new Array(bytes.length);
  23.     for (var i:int = 0, n:int = bytes.length / 4; i < n; ++i)
  24.       samples[i] = bytes.readFloat();
  25.     ExternalInterface.call('samples', samples);
  26.   }
  27. }
  28. function error(event:Event):void {
  29.   ExternalInterface.call('error');
  30. }
Add Comment
Please, Sign In to add comment