AIR3 ios app microphone recording/playing problem - beginning of recording is missing
saariko Oct 4, 2011 2:10 PMhey
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. also works fine on an android device.
same problem when deploying on iPhone4
if anyone could try this code and see if he/she reproduces this, i would appreciate it
thanks
Saar
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.addEventListener(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);
}
}
}
}
Message was edited by: saariko
Message was edited by: saariko

