diff --git a/flash/Recorder.as b/flash/Recorder.as index fdad5e5..8bc8355 100644 --- a/flash/Recorder.as +++ b/flash/Recorder.as @@ -1,9 +1,13 @@ -package +package { import com.adobe.audio.format.WAVWriter; import flash.events.TimerEvent; import flash.events.Event; import flash.events.ErrorEvent; + import flash.events.HTTPStatusEvent; + import flash.events.IOErrorEvent; + import flash.events.ProgressEvent; + import flash.events.SecurityErrorEvent; import flash.events.SampleDataEvent; import flash.external.ExternalInterface; import flash.media.Microphone; @@ -17,19 +21,19 @@ package import flash.system.SecurityPanel; import flash.events.StatusEvent; import flash.utils.getQualifiedClassName; - + import mx.collections.ArrayCollection; - + import ru.inspirit.net.MultipartURLLoader; - + public class Recorder { public function Recorder(logger) { this.logger = logger; } - + private var logger; public function addExternalInterfaceCallbacks():void { ExternalInterface.addCallback("record", this.record); @@ -45,7 +49,6 @@ package logger.log("Recorder initialized"); } - protected var isRecording:Boolean = false; protected var isPlaying:Boolean = false; protected var microphoneWasMuted:Boolean; @@ -56,10 +59,10 @@ package protected var channel:SoundChannel; protected var recordingStartTime = 0; protected static var sampleRate = 44.1; - + protected function record():void { - if(!microphone){ + if(!microphone){ setupMicrophone(); } @@ -74,7 +77,7 @@ package buffer = new ByteArray(); microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, recordSampleDataHandler); } - + protected function recordStop():int { logger.log('stopRecording'); @@ -83,7 +86,7 @@ package microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, recordSampleDataHandler); return recordingDuration(); } - + protected function play():void { logger.log('startPlaying'); @@ -92,12 +95,12 @@ package buffer.position = 0; sound = new Sound(); sound.addEventListener(SampleDataEvent.SAMPLE_DATA, playSampleDataHandler); - + channel = sound.play(); channel.addEventListener(Event.SOUND_COMPLETE, function(){ playStop(); - }); - + }); + if(playingProgressTimer){ playingProgressTimer.reset(); } @@ -108,32 +111,32 @@ package }); playingProgressTimer.start(); } - + protected function stop():int { playStop(); return recordStop(); } - + protected function playStop():void { logger.log('stopPlaying'); if(channel){ channel.stop(); playingProgressTimer.reset(); - + triggerEvent('playingStop', {}); isPlaying = false; } } - - /* Networking functions */ - + + /* Networking functions */ + protected function upload(uri:String, audioParam:String, parameters): void { logger.log("upload"); buffer.position = 0; - var wav:ByteArray = prepareWav(); + var wav:ByteArray = prepareWav(); var ml:MultipartURLLoader = new MultipartURLLoader(); ml.addEventListener(Event.COMPLETE, onReady); function onReady(e:Event):void @@ -141,7 +144,35 @@ package triggerEvent('uploadSuccess', externalInterfaceEncode(e.target.loader.data)); logger.log('uploading done'); } - + + ml.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatusEvent); + function onHTTPStatusEvent(e:HTTPStatusEvent):void + { + triggerEvent('uploadHttpStatus', externalInterfaceEncode(e.target.loader.data)); + logger.log('http status error occured during upload'); + } + + ml.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorEvent); + function onIOErrorEvent(e:IOErrorEvent):void + { + triggerEvent('uploadIoError', externalInterfaceEncode(e.target.loader.data)); + logger.log('io error occured during upload'); + } + + ml.addEventListener(ProgressEvent.PROGRESS, onProgressEvent); + function onProgressEvent(e:ProgressEvent):void + { + triggerEvent('uploadProgress', externalInterfaceEncode(e.target.loader.data)); + logger.log('upload progress'); + } + + ml.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityErrorEvent); + function onSecurityErrorEvent(e:SecurityErrorEvent):void + { + triggerEvent('uploadSecurityError', externalInterfaceEncode(e.target.loader.data)); + logger.log('security Error occured during upload'); + } + if(getQualifiedClassName(parameters.constructor) == "Array"){ for(var i=0; i is released under the MIT License is released under the MIT License 0){for(var af=0;af0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad'}}aa.outerHTML='"+af+"";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab