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

前端 未结 5 2015
别那么骄傲
别那么骄傲 2021-01-14 12:22

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

相关标签:
5条回答
  • 2021-01-14 12:57

    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

    0 讨论(0)
  • 2021-01-14 13:01
    `if (audioRecorder != null) {
                try {
                    audioRecorder.stop();
                    audioRecorder.reset();
                    audioRecorder.release();
                    audioRecorder = null;
                    
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                }
            }`
    

    Because we are not releasing recorder and only stopping the recorder on relaunch we get at android.media.MediaRecorder.start(Native Method) took 1 hrs to figure out

    HappyCoding

    0 讨论(0)
  • 2021-01-14 13:02

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


    0 讨论(0)
  • 2021-01-14 13:03

    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();
    
    0 讨论(0)
  • 2021-01-14 13:05

    Caused by: java.lang.IllegalStateException at android.media.MediaRecorder.native_start(Native Method)

    I was facing issue regarding media recorder. It was recording perfect but one i try to record the screen again then i get this error and media recorder gets crashed. After trying many things and tatics i tried this mediarecorder.release(); with this method every time i stop the recording the media recorder gets released and enables me to record again.

    0 讨论(0)
提交回复
热议问题