开发者

AIR3 ios app microphone recording/playing - beginning of recording is missing

开发者 https://www.devze.com 2023-04-11 06:04 出处:网络
i have build a small test app in Flash Pro 5.5 overlayed with the AIR 3 sdk. is has just 2 buttons to record and playback audio from the microphone.

i have build a small test app in Flash Pro 5.5 overlayed with the AIR 3 sdk. is has just 2 buttons to record and playback audio from the microphone.

when i test this on my iPhone 3g - i record myself saying "1-2-3-4-5". but when i playback a half a second or so is missing from the beginning : "3-4-5-".

when i test this on the desktop all is fine

is this a result of the iPhone 3g's cpu power or is it a bug or is it my code?

thanks Saar

if anyone could try this code and see if he/she reproduces this, i would appreciate it

this is the app:

all i have on stage is 2 rectangled movie clips named "recorded" and "player" all the code is in this document class:

package  {

          import flash.display.MovieClip;
          import flash.media.Microphone;
          import flash.media.SoundMixer;
          import flash.events.MouseEvent;
          import flash.utils.ByteArray;
          import flash.media.Sound;
          import flash.media.SoundChannel;
          import flash.events.SampleDataEvent;
          import flash.media.AudioPlaybackMode;


          public class RecTest extends MovieClip {
                    var mic:Microphone;
                    var nowRecording:Boolean = false;
                    var nowPlaying:Boolean = false;
                    var recordedBytes:ByteArray = new ByteArray();
                    var s:Sound = new Sound();
                    var sc:SoundChannel;

                    public function RecTest() {
                              mic = Microphone.getMicrophone(-1);
                              SoundMixer.useSpeakerphoneForVoice = true;
                              SoundMixer.audioPlaybackMode = AudioPlaybackMode.MEDIA;
                              mic.gain = 100;
                              mic.setSilenceLevel(0);
                              mic.rate = 44;

                              recorder.addEventListener(MouseEvent.CLICK, onRec);
                              player.addEventLi开发者_C百科stener(MouseEvent.CLICK, onPlay);
                    }

                    function onRec(e:MouseEvent) {
                              if (nowRecording) {
                                        trace("stopped");
                                        mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio);
                                        nowRecording = false;
                              } else {
                                        trace("recording");
                                        recordedBytes.position = 0;
                                        recordedBytes.length = 0;
                                        mic.addEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio);
                                        nowRecording = true;
                              }
                    }

                    function onPlay(e:MouseEvent) {
                              if (nowPlaying) {
                                        trace("stopped");
                                        sc.stop();
                                        s.removeEventListener(SampleDataEvent.SAMPLE_DATA, playAudio);
                                        nowPlaying = false;
                              } else {
                                        trace("playing");
                                        recordedBytes.position = 0;
                                        s.addEventListener(SampleDataEvent.SAMPLE_DATA, playAudio);
                                        sc = s.play();
                                                sc.addEventListener(Event.SOUND_COMPLETE, onComplete,false,0,true);
                                        nowPlaying = true;
                              }
                    }

                        function onComplete(e:Event) {
                                              trace("stopped");
                                              s.removeEventListener(SampleDataEvent.SAMPLE_DATA, playAudio);
                                              nowPlaying = false;
                    }


                    function getMicAudio(e:SampleDataEvent) {
                              recordedBytes.writeBytes(e.data);
                    }

                    function playAudio(e:SampleDataEvent) {
                              for (var i:int = 0; i < 8092 && recordedBytes.bytesAvailable > 0; i++) {
                                        e.data.writeBytes(recordedBytes);
                                        e.data.writeBytes(recordedBytes);
                              }
                    }
          }

}


I suggest that you use a swipe feature to start recording. As a workaround you could start recording when the user initializes the swipe gesture. Hopefully the recording will have begun when the gesture is finished.

If you try this - let us know how this works


ok, this seems to be a lag in the iOS recording. so i use a workaround: constant recording to a buffer and using the buttons to record the in and out positions of the ByteArray for playback


Try listening for the flash.events.ActivityEvent-event. There might be a small delay before the mic actually starts recording.


Try to get hold of recorded file (U need to ssh iphone and get the file under Apps dir) and see if there is a delay in recording or delay in playback.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号