MediaRecorder crashes on start

后端 未结 8 1733
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 12:25

i\'ve searched many topics but no straight answer.

I have this code :

        recorder = new MediaRecorder();
    recorder.setAudioSource(MediaRecord         


        
相关标签:
8条回答
  • 2020-12-06 12:50

    Try putting the start function in the same block as prepare function. maybe there's an exception blocking prepare from executing and goes directly to start thus causing an IllegalStateException.

        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setOutputFormat(output_formats[currentFormat]);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        recorder.setOutputFile(getFilename());
    
    
        try {
            recorder.prepare();
            recorder.start();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    
    0 讨论(0)
  • 2020-12-06 12:52

    Try to start your recorder only when it is prepared :

        try {
            recorder.prepare();
            recorder.start();
            mStartRecording = true;
        }  catch (IOException e) {
            Log.e( LOG_TAG, "Error when preparing or starting recorder", e);
        }
    
    0 讨论(0)
提交回复
热议问题