android mediaRecorder.setAudioSource failed

user121196 picture user121196 · Sep 23, 2010 · Viewed 69.4k times · Source

I have android G1 firmware 1.6, I am trying to record voice from the app with the follow code.

MediaRecorder recorder = new MediaRecorder();
 recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
 recorder.setOutputFile(PATH_NAME);
 recorder.prepare();
 recorder.start();  

my manifest.xml has:

<uses-permission android:name="android.permission.RECORD_AUDIO" />

I got:

09-23 14:41:05.531: ERROR/AndroidRuntime(1718): Uncaught handler: thread main exiting due to uncaught exception
09-23 14:41:05.551: ERROR/AndroidRuntime(1718): java.lang.RuntimeException: setAudioSource failed.
09-23 14:41:05.551: ERROR/AndroidRuntime(1718):     at android.media.MediaRecorder.setAudioSource(Native Method)

how do I record voice properly?

Answer

Steve Ham picture Steve Ham · Dec 28, 2012

Open "AndroidManifest.xml" ->

add

<uses-permission android:name="android.permission.RECORD_AUDIO" />