I've seen posts regarding problems with the AudioRecord
OnRecordPositionUpdateListener, but I haven't seen any real answers.

I'm using AudioRecord to record from the mic, and I want to get the
input from the mic periodically so I can check sound levels and update
a meter.  I set up the listener like this:

        private OnRecordPositionUpdateListener mRecordListener = new
AudioRecord.OnRecordPositionUpdateListener()
        {
                public void onPeriodicNotification(AudioRecord recorder) {
                        if 
(recorder.getRecordingState()!=aRecorder.RECORDSTATE_STOPPED)
                        {
                                mAudioBuffer = new short[8000];
                                mSamplesRead = recorder.read(mAudioBuffer, 0, 
8000);
                                if (mSamplesRead > 0)
                                {
                                        // do something
                                }
                        }
                }

                public void onMarkerReached(AudioRecord recorder)
                {
                        if 
(recorder.getRecordingState()!=aRecorder.RECORDSTATE_STOPPED)
                        {
                                mAudioBuffer = new short[8000];
                                mSamplesRead = recorder.read(mAudioBuffer, 0, 
8000);
                        }
                }
        };

I instantiate the AudioRecord object like this:

                        // audioSource = MediaRecorder.AudioSource.MIC
                        // sampleRate = 16000
                       // channelConfig = AudioFormat.CHANNEL_IN_MONO
                       // audioFormat = AudioFormat.ENCODING_PCM_16BIT
                       // bufferSize = 409600

                        aRecorder = new AudioRecord(audioSource, sampleRate, 
channelConfig,
audioFormat, bufferSize);
                        if (aRecorder.getState() != 
AudioRecord.STATE_INITIALIZED)
                                throw new Exception("AudioRecord initialization 
failed");
                        
aRecorder.setRecordPositionUpdateListener(mRecordListener);
                        aRecorder.setPositionNotificationPeriod(400);
                        aRecorder.setNotificationMarkerPosition(400);

What happens is that onMarkerReached gets called once, after the
recorder is released, so that's not very useful.

Do I need to change the marker position and notification period?  Is
the listener working?  Is there another way to accomplish periodically
getting the mic input?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to