Wednesday 15 February 2012

ios - SampleDataEvent not fired after second audio recording on mobile -



ios - SampleDataEvent not fired after second audio recording on mobile -

i have unusual behavior when playing recorded sound microphone on ios device sec time.

goal:

what want accomplish app can record multiple sound files buildin microphone, has possible re-record existing audio.

the troubles:

the first time record sound microphone , want play after finishing record works charm. sound plays fine.

the sec time want record sound same byteaarray or new bytearray, , want play recorded audio. sampledataevent.sample_data fired few times stops after 4-6 times , notting. app not crash, dont errors. when exit app (press home button on ipad) , after open app 1 time again sound starts play. sampledata fired 1 time again , app works fine. here if record new audio, not play. exit app, open 1 time again , it's playing.

recording code (audiorecord.as):

public function activate():void { // mic = microphone.getmicrophone(); mic.setsilencelevel(0); mic.gain = 50; mic.rate = 44; } public function startrecord():void { trace("start sound record"); isrecording = true; recordtime = 0; // soundbytes = null; soundbytes = new bytearray(); mic.addeventlistener(sampledataevent.sample_data, micsampledatahandler); } private function micsampledatahandler(event:sampledataevent):void { while (event.data.bytesavailable) { var sample:number = event.data.readfloat(); soundbytes.writefloat(sample); } }

play sound code (audiobytesplayer.as):

public function playsound(bytes:bytearray):void { trace("audiobytesplayer - startsound"); isplaying = true; sounddata = bytes; sounddata.position = 0; sound.addeventlistener(sampledataevent.sample_data, playbacksamplehandler); soundchannel.addeventlistener(event.sound_complete, onsc); soundchannel = sound.play(); } private function playbacksamplehandler(event:sampledataevent):void { trace("playbacksamplehandler"); (var i:int = 0; < 8192; i++) { if (sounddata.bytesavailable < 2) { stopsound(); break; } var sample:number = sounddata.readfloat(); event.data.writefloat(sample); event.data.writefloat(sample); } }

hope guys can help me out.

it appears since update ios 8 problem occurs. on ios 7 devices works sweet. hope adobe or apple comes prepare

ios actionscript-3 audio bytearray audio-recording

No comments:

Post a Comment