I am having a couple of problems recording sound on a device. The code I am using if from the android dev site (Site Link) and is as follows:
public void onClickStart(View v) throws IllegalStateException, IOException{
startRecord();
}
public void onClickStop(View v) throws IllegalStateException, IOException{
stopRecord();
}
private void startRecord() throws IllegalStateException, IOException{
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC); //ok so I say audio source is the microphone, is it windows/linux microphone on the emulator?
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile("/sdcard/test.3gpp");
recorder.prepare();
recorder.start();
}
private void stopRecord(){
recorder.stop();
// recorder.release();
}
With 2 buttons in the main layout which it turn both stop and start the recording (in theory that is).
But from LogCat when trying this out on my device (really cant be bothered with trying on the emulator) I get the following errors:
Error 1:
ERROR/MediaRecorder(14541): start called in an invalid state: 4
java.lang.IllegalStateException: Could not execute method of the activity
Caused by: java.lang.reflect.InvocationTargetException
Error 2:
Caused by: java.io.FileNotFoundException: /sdcard/test.3gpp (Permission denied)
And I also have the following permissions set in my Manifest.xml file:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />