Tutorial :AudioRecord doesn't work for Motorola Milestone


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://web.archive.org/web/20100824043744/http://androidcommunity.com:80/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


This should work:

recordInstance = new AudioRecord(MediaRecorder.AudioSource.MIC,  16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, 16000);  

Just stick to the standard sample rates http://en.wikipedia.org/wiki/Sampling_rate#Audio. I wonder why Milestone does not support recording with 8bit encoding. This gives me an error too - "Invalid audio format".


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.


The issue is not parameters, the issue is a bug with Motorola's tinkering of Android, the AudioRecord will not create itself properly if the mode is IN_CALL, if its MODE_NORMAL it should be fine.

This is because something in Motorolas code hogs the input when its IN_CALL mode.


Theoretically, the hcpl's code should work because the speech sampling is 8kHz but some android devices doesn't accept it.

Completing the mad answer, from the Android Developers website:

sampleRateInHz int: the sample rate expressed in Hertz. 44100Hz is currently the only rate that is guaranteed to work on all devices, but other rates such as 22050, 16000, and 11025 may work on some devices. AudioFormat.SAMPLE_RATE_UNSPECIFIED means to use a route-dependent value which is usually the sample rate of the source. getSampleRate() can be used to retrieve the actual sample rate chosen.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »