Skip to main content
Douglas McCarroll
Inspiring
May 14, 2013
Answered

Problem with Microphone on iOS - bug or incorrect code?

  • May 14, 2013
  • 1 reply
  • 3342 views

Hi All,

It appears that using the Microphone class is freezing my Flex mobile app. I provide code below but here's an overview:

  • This only happens on iOS - specifically my iPhone 4. I haven't seen this problem on Android devices.
  • My code alternates between recording and not recording - 5 seconds of one, then 5 seconds of the other, then repeat over and over.
  • I've reduce this to a "minimal case" example (see code below) that does nothing but this. It doesn't use the data that comes in from the Microphone, doesn't create or populate a ByteArray, etc.
  • The app always crashes. In some cases this happens when it's been running for only 2-3 minutes, in all cases it happens within a half hour. I've done 10 test runs and the average is 15 minutes.

My app is a language learning app, and recording and playback of the user's voice is an important feature. It allows the user to hear how well their pronunciation matches that of a native speaker. When record/playback is turned on the app repeatedly plays some audio, records the user's voice, plays it back, plays more audio, etc. In other words, it includes functionality similar to the minimal case code that I'm including here. Users often use this functionality 30 minutes or longer. So this is a problem. 

Am I doing something wrong in my code? Just checking before I report this as a bug.

You can download an FXP from here if you're interested:

http://www.brightworks.com/downloads/RecordingTest.fxp

Or, the important code is below. This is from the example app's (only) view.

Thanks,

Douglas

Douglas McCarroll

Brightworks, Inc.

320.300.0220

<?xml version = "1.0" encoding = "utf-8"?>

<s:View xmlns:fx = "http://ns.adobe.com/mxml/2009"

        xmlns:s = "library://ns.adobe.com/flex/spark"

        creationComplete = "onCreationComplete()"

        title = "Recording Test">

    <fx:Declarations>

    </fx:Declarations>

    <fx:Script>

        <![CDATA[

            private var _isRecording:Boolean;

            private var _iterationCount:uint = 0;

            private var _microphone:Microphone;

            private var _recordedSeconds:uint = 0;

            private var _timer:Timer;

            private function onCreationComplete():void

            {

                NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

            }

            private function doNextPhase(event:TimerEvent = null):void

            {

                _isRecording = !_isRecording;

                if (_isRecording)

                {

                    _iterationCount++;

                    displayOutput("Recording");

                    _microphone = Microphone.getMicrophone();

                    _microphone.rate = 44;

                    _microphone.gain = 50;

                    _microphone.setSilenceLevel(0, 2000);

                    _microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, onNewRecordingSampleData);

                }

                else

                {

                    _recordedSeconds += 5;

                    displayOutput("Pausing");

                    _microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, onNewRecordingSampleData);

                    _microphone = null;

                }

            }

            private function onNewRecordingSampleData(event:SampleDataEvent):void

            {

            }

            private function displayOutput(phase:String):void

            {

                var freeMemoryMB:int = Math.round(System.freeMemory / (1024 *1024));

                var privateMemoryMB:int = Math.round(System.privateMemory / (1024 *1024));

                var totalMemoryNumberMB:int = Math.round(System.totalMemoryNumber / (1024 *1024));

                phaseLabel.text = "Phase: " + phase;

                iterationLabel.text = "Iteration: " + _iterationCount;

                recordedSecondsLabel.text = "Recorded Seconds: " + _recordedSeconds;

                freeMemoryLabel.text = "System.freeMemory MB: " + freeMemoryMB;

                privateMemoryLabel.text = "System.privateMemory MB: " + privateMemoryMB;

                totalMemoryNumberLabel.text = "System.totalMemoryNumber MB: " + totalMemoryNumberMB;

            }

            private function startTimer():void

            {

                _timer = new Timer(5000, 0);

                _timer.addEventListener(TimerEvent.TIMER, doNextPhase);

                _timer.start();

            }

            private function onStartRecordingButtonClick():void

            {

                if ((Microphone.getMicrophone()))

                {

                    startRecordingButton.enabled = false;

                    startTimer();

                    doNextPhase();

                }

                else

                {

                    phaseLabel.text = "No Mic Available";

                }

            }

        ]]>

    </fx:Script>

    <s:VGroup height = "100%"

              width = "100%"

              paddingBottom = "20"

              paddingLeft = "20"

              paddingRight = "20"

              paddingTop = "20">

        <s:Label id = "phaseLabel"

                 width = "100%" />

        <s:Label id = "iterationLabel"

                 width = "100%" />

        <s:Label id = "recordedSecondsLabel"

                 width = "100%" />

        <s:Label id = "freeMemoryLabel"

                 width = "100%" />

        <s:Label id = "privateMemoryLabel"

                 width = "100%" />

        <s:Label id = "totalMemoryNumberLabel"

                 width = "100%" />

    </s:VGroup>

    <s:HGroup width = "100%"

              horizontalAlign = "center"

              bottom = "10">

        <s:Button id = "startRecordingButton"

                  label = "Start Recording"

                  click = "onStartRecordingButtonClick()"

                  width = "60%" />

    </s:HGroup>

</s:View>

This topic has been closed for replies.
Correct answer globzie

I don't have 3.5.0.600, but I have 3.5.0.1060. I've tried it and it appears to, if anything, make the problem worse. 

Also, in any case, I have to use 3.6 so that I can target iPhone 5 (see http://forums.adobe.com/thread/1198630). Perhaps, if one is only targeting iPad, one can use 3.5 as a workaround, but otherwise 3.5 isn't really an option, right?


The issue has been solved with 3.8.0.730 !

http://forums.adobe.com/message/5399512#5399512 ;-)

Thanks Adobe!

1 reply

Adobe Employee
May 15, 2013

We have been able to reproduce the issue. Could you please open a new bug report on this over at bugbase.adobe.com? When adding the bug please add the SDK , iOS version you are using? Once added, please post back with the bug URL/number so that other can affected.

Regards,

Nimit

Douglas McCarroll
Inspiring
May 15, 2013

> We have been able to reproduce the issue.

Great!  

> please open a new bug report

Done...

https://bugbase.adobe.com/index.cfm?event=bug&id=3560896