Skip to main content
Inspiring
October 13, 2011
Answered

anyone successfully recording mic audio and playing it back on ios?

  • October 13, 2011
  • 3 replies
  • 4069 views

hey all

i am having a lot of annoying problems with recording microphone audio and playing it back on the iPhone (same app works flawlessly on desktop and android)

has any of you successfully done that?

Saar

This topic has been closed for replies.
Correct answer saariko

ok i have some answers

Divij Kumar, thanx for the how-to, but i never got to packaging your swf since compiling my own project with "Deployment - Apple App Store" instead of "Quick publishing for device debugging" did the trick.

The app then worked fine.

the quick publishing was the problem, at least in my case

THANX ALL

btw, the recording starts a bit late on my iPhone 3Gs - but this is the iOS's fault - i checked and the built-in app "Voice Memos" is also late. I need in my app instant recording so I have a constant buffer recording and i use the buttons to mark in and out points instead of adding and removing SampleEvents listeners like we all did here.

cheers

3 replies

saarikoAuthorCorrect answer
Inspiring
October 18, 2011

ok i have some answers

Divij Kumar, thanx for the how-to, but i never got to packaging your swf since compiling my own project with "Deployment - Apple App Store" instead of "Quick publishing for device debugging" did the trick.

The app then worked fine.

the quick publishing was the problem, at least in my case

THANX ALL

btw, the recording starts a bit late on my iPhone 3Gs - but this is the iOS's fault - i checked and the built-in app "Voice Memos" is also late. I need in my app instant recording so I have a constant buffer recording and i use the buttons to mark in and out points instead of adding and removing SampleEvents listeners like we all did here.

cheers

saarikoAuthor
Inspiring
October 16, 2011

@Varun Bhatia,

i have some new info

deactivating the app manually and reactivating it again before playback makes most problems go away. (pressing the hardware iPhone button and then pressing the app icon to reactivate)

this feels like a problem AIR has with acquistioning sound channels from the iOS

Pahup
Adobe Employee
Adobe Employee
October 17, 2011

Saariko,

I've not been able to reproduce the problem, I used your code only.

Could you please tell us step by step what exactly you do to see problem reproducing.

I mean what button you press(recorder or player) first after launch, then you press recorder button again or you press player button, then what yo do next..etc.

What I did is as following.

I launched the app, pressed recorder button, recorded some sound, pressed recorder button to stop recording, pressed player button and it played the recording, I did not observe any stuttering here.

You can try with the swf/xml that I've attached.

Also, which device and OS version you're on, do you have many other applications running in background?

Thanks for your support.

-Pahup

saarikoAuthor
Inspiring
October 17, 2011

the steps you took are correct. i have done the same.

to be sure, i closed ALL apps on my iPhone except for my app.  the problem remains.

i am using an iPhone 3Gs running 4.3.5

i will be able to test your swf and also test on other iOS devices only later. i will let u know

thanx a lot!

Adobe Employee
October 16, 2011

Can you specify what problem you are exactly facing so that we can help you around that.

saarikoAuthor
Inspiring
October 16, 2011

@Varun Bhatia,

yes i can

my simple recording test app works great on the desktop and on Android.

on the other hand, on ios (iPhone 3gs, latest os) i sometimes hear nothing on playback, sometimes just the end of the recording, sometimes the playback is stuttering.

thanx,

Saar

i am using flash pro cs5.5 overlayed with the AIR 3 sdk.

the FLA contains two movieclips on stage named "recorder" and "player". they act as buttons. all the code is in the document class:

package  {

          import flash.display.Sprite;

          import flash.media.Microphone;

          import flash.media.Sound;

          import flash.media.SoundChannel;

          import flash.events.MouseEvent;

          import flash.events.SampleDataEvent;

          import flash.utils.ByteArray;

          import flash.events.Event;

          import flash.media.SoundMixer;

          import flash.media.AudioPlaybackMode;

          public class RecTest extends Sprite {

                    var mic:Microphone;

                    var s:Sound;

                    var sc:SoundChannel;

                    var nowRecording:Boolean = false;

                    var nowPlaying:Boolean = false;

                    var recordedBytes:ByteArray;

                    public function RecTest() {

                              SoundMixer.audioPlaybackMode = AudioPlaybackMode.MEDIA;

                              mic = Microphone.getMicrophone();

                              mic.rate = 44;

                              mic.gain = 70;

                              mic.setSilenceLevel(0);

                              s = new Sound();

                              recordedBytes = new ByteArray();

                               recorder.addEventListener(MouseEvent.CLICK, record);

                               player.addEventListener(MouseEvent.CLICK, playBack);

                    }

                    function record(e:MouseEvent) {

                              if (!nowRecording) {

                                        trace("recording");

                                        recordedBytes.clear();

                                        mic.addEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio);

                                        nowRecording = true;

                              } else {

                                        trace("recording stopped");

                                        mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio);

                                        nowRecording = false;

                              }

                    }

                    function getMicAudio(e:SampleDataEvent) {

                              recordedBytes.writeBytes(e.data);

                    }

                    function playBack(e:MouseEvent) {

                              if (!nowPlaying) {

                                        trace("playing");

                                        recordedBytes.position = 0;

                                        s.addEventListener(SampleDataEvent.SAMPLE_DATA, playAudio);

                                        sc = s.play();

                                        sc.addEventListener(Event.SOUND_COMPLETE, stopPlayback, false, 0, true);

                                        nowPlaying = true;

                              } else {

                                        sc.stop();

                                        stopPlayback();

                              }

                    }

                    function stopPlayback(e:Event=null) {

                              trace("playing stopped");

                              s.removeEventListener(SampleDataEvent.SAMPLE_DATA, playAudio);

                              nowPlaying = false;

                    }

                    function playAudio(e:SampleDataEvent) {

                              for (var i:int = 0; i < 8092 && recordedBytes.bytesAvailable > 0; i++) {

                                        var sample:Number = recordedBytes.readFloat();

                                        e.data.writeFloat(sample);

                                        e.data.writeFloat(sample);

                              }

                    }

          }

}