tags:

views:

287

answers:

4

I'm having this problem only on Motorola Milestone. Code:

// init recorder
recordInstance = new AudioRecord(MediaRecorder.AudioSource.MIC,
    8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
    AudioFormat.ENCODING_PCM_16BIT, 8000);

recordInstance.startRecording();

//more code here

recordInstance.stop();

The errorinformation I have (can't find more for the moment since I don't have a milestone myself for debugging):

Uncaught handler: thread main exiting due to uncaught exception
java.lang.IllegalStateException: stop() called on an uninitialized AudioRecord.
at android.media.AudioRecord.stop(AudioRecord.java:51 6)

Apparantly I'm not the only one with this problem. Some very similar threads I found (without solution):

http://groups.google.com/group/android-developers/browse_thread/thread/6dd24aeb484b2e40 http://androidcommunity.com/forums/f2/problem-using-audiorecord-in-motorola-milestone-30935/ http://community.developer.motorola.com/t5/Android-App-Development-for/Problem-using-AudioRecord-on-Milestone-device/m-p/3889 http://www.fring.com/forums/showthread.php?t=16194 http://groups.google.com/group/android-developers/browse_thread/thread/63be273ba59c635e/1c4a010fd470d328

A: 

Firstly as it says try putting a try catch block over the stop, as the debugs message is saying, the recording is getting into an IllegalState.

Probably if u can catch the exception, you can find out what the problem is.

the100rabh
I did but couldn't get any more information than the reported java.lang.IllegalStateException with messages:android startRecording called on an uninitialized AudioRecord
hcpl
You can check the state using getState function so that u can atleast avoid a crash. This crash is because for some reason your recording is not initialised. Best done right after you have started and then throw an appropriate error message.
the100rabh
Thanks for the answer. I understand I'll have to add some try catch but I was wondering if anyone knows what values for what devices work? As I believe these are vendor specific?
hcpl
A: 

Hi I am facing issue with following parameter

audioRecord =new AudioRecord(MediaRecorder.AudioSource.MIC, 11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_8BIT, 5000);

getting exception

android startRecording called on an uninitialized AudioRecord

sohilv
Are you also having problems?According to API this ctor throws IllegalStateException like we get (I can't test for devices other than hero).What device are you testing on? Did you try different params? Like another sampleRateInHz or encoding?According to API these are the params: public AudioRecord (int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes)sampleRateInHz the sample rate expressed in Hertz. Examples of rates are (but not limited to) 44100, 22050 and 11025.
hcpl
A: 

I have the same exact problem. Perhaps the AudioRecord object is uninitialized because the parameters are not compatible with the device. I don't have a milestone to test with, but on my Nexus One, Cliq XT, Behold II and the Emulator, the following parameters work:

audioRecord =new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT,  
AudioRecord.getMinBufferSize(8000,AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT) );

autoRecord.startRecording(); // will throw an exception, based upon phone type

The above works fine on: Nexus One, Samsung Behold II, Cliq XT and the emulator. I've heard that it does not work on the: LG Ally (and possibly Moto Milestone/Droid). Perhaps someone can test it out on those devices and tell us what parameters do work.

Yahma
Yes please, someone have this kind of tests on a motorola. Thanks for bumping up my question. Since I didn't find anyone willing to test this in depth I still haven't got a solution.
hcpl
A: 

I have tested with exactly above parameters on my Droid, apparenty it still crashes although the case is not always. (most of the time it works, but sometimes I still could find the problem)

Ahmad
do you know parameters that do work all the time?
hcpl