-1

I have a strange behavior when playing a recorded audio from the microphone on my ios device for the second time.

Goal:

what i want to achieve is an app where we can record multiple audio files with the buildin microphone, also it has to be possible to re-record an existing audio.

The troubles:

The first time i record an audio from the microphone and want to play it after finishing the record it works like a charm. Audio plays fine.

The second time i want to record an audio with the same byteaArray or a new byteArray, and want to play the recorded audio. The SampleDataEvent.SAMPLE_DATA is fired a few times but stops after 4-6 times and then does notting. The app does not crash, i dont get any errors. When i exit the app (press home button on the iPad) and after that open the app again the audio starts to play. SampleData is fired again and the app works fine. But also here if i record a new audio, it does not play. Exit app, open it again and 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 audio 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 audio 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");
        for (var i:int = 0; i < 8192; i++) {
            if (soundData.bytesAvailable < 2) {
                stopSound();
                break;
            }
            var sample:Number = soundData.readFloat();
            event.data.writeFloat(sample);
            event.data.writeFloat(sample);
        }
    }

Hope you guys can help me out.

2
  • That's a lot of code; would it be possible to post only the code that reliably produces your error, so it's easier to help you?
    – APerson
    Oct 7, 2014 at 13:16
  • i've removed some code, but the part that reproduces the error is not clear. The first time i record and play, all works fine. only the second time playing result in not firing the Event.SOUND_COMPLETE, and soundData.bytesAvailable is > 2
    – Suur
    Oct 7, 2014 at 13:43

1 Answer 1

0

It appears that since the update to IOS 8 this problem occurs. On IOS 7 devices it all works sweet. Hope adobe or apple comes with a fix

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.