Quantcast
Channel: Adobe Community : Popular Discussions - AIR Development
Viewing all articles
Browse latest Browse all 24121

Problem with Microphone on iOS - bug or incorrect code?

$
0
0

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>


Viewing all articles
Browse latest Browse all 24121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>