java.lang.IllegalStateException at android.media.MediaRecorder.start(Native Method)

偶尔善良 提交于 2019-12-01 11:01:11

you are forgetting to call recorder.prepare() before recordeer.start() function in your beginRecording function.

Prepare function will take care about lot of things like conversion of analog data to digital audio for compresion and where to store the file etc

You have to take into consideration, that MediaRecorder as well as MediaPlayer has their state machines, which obligate you to do some action in specific sequence.

Here you tried to start recording withou preparing MediaRecorder. Call

recorder.prepare();

Before:

recorder.start();

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();
}


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!