I want to make a voice recorder app but it crashes when i click the \"Start Recording\" button. I get an error saying java.lang.IllegalStateException at android.media.Media
Call this after setOutFormat() but before prepare().
this is just what my android studio docs dialog says while i write this method name.
the point is that you should call this method just before prepare().
here is an example:
private void startRecording() {
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
File outputFolder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MediaMaster/Dub/");
Log.i(TAG, "startRecording: creating output file " + outputFolder.mkdirs());
File output = new File(outputFolder.getAbsolutePath()+"out" + new Date().getTime() + ".3gpp");
mediaRecorder.setOutputFile(output.getAbsolutePath());
mediaRecorder.setMaxDuration(3000);
try {
mediaRecorder.prepare();
} catch (IOException e) {
Log.e(TAG, "startRecording: ", e);
}
mediaRecorder.start();
}