IllegalStateException with MediaRecorder.start (): null

I am trying to create a simple video recorder, and here is my code to call it:

protected boolean prepareForVideoRecording() {
    try {
        mCamera.unlock();
        mMediaRecorder = new MediaRecorder();
        mMediaRecorder.setCamera(mCamera);
        mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
        mMediaRecorder.setOutputFile(getOutputMediaFile1(MEDIA_TYPE_VIDEO).toString());
        mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
        try {
            mMediaRecorder.prepare();
            Toast.makeText(getContextOfMainFragment(), "Prepared!", Toast.LENGTH_SHORT).show();
        } catch (IllegalStateException e) {
            Log.e(TAG,"IllegalStateException when preparing MediaRecorder "+ e.getMessage());
            e.getStackTrace();
            releaseMediaRecorder();
            return false;
        } catch (IOException e) {
            Log.e(TAG,"IOException when preparing MediaRecorder "+ e.getMessage());
            e.getStackTrace();
            releaseMediaRecorder();
            return false;
        }
        return true;

    } catch (Exception e) {
        return false;
    }
}

Please ignore the toasts, I sometimes use them for debugging. Then it remains only to call mMediaRecorder.start () I do it with the click of a button. In fact, I added 2 buttons, the 1st button calls this method above, another button launches the call. I am sure that the same code worked for me once, I do not know why it does not work anymore.

I added an attempt to catch my call to mMediaRecorder.start () with IllegalStateException and this is what I got:

04-09 10:38:18.350: E/MediaRecorder(29678): start failed: -38
04-09 10:38:18.350: E/VideoTut_Main(29678): Illegal state exception with MediaRecorder.Start() :  null
0
source share
1 answer

. , ( , ) Android- Android, , . , , . :

  • , .., - , , , .
  • , . Android 4.0 . , , Nexus 5. , , (Xperia ray ), .
  • , getSupportedVideoSizes() .

1. 3. , , MediaRecorder.OutputFormat.THREE_GPP, MediaRecorder.AudioEncoder.AMR_NB MediaRecorder.VideoEncoder.MPEG_4_SP.

Video Timer Google Play, , , Nexus 5.

+2

Source: https://habr.com/ru/post/1567982/


All Articles