MediaRecorder gives start error or IllegalStateException

The problem is that you're not setting the camera, using Camera 1 API you should first open the camera, then unlock it and set it to the recorder. Only after that you can continue with the configuration of MediaRecorder (which is btw a very beautifully written piece of API)

MediaRecorder recorder = new MediaRecorder();

Camera camera = Camera.open();
camera.unlock();
recorder.setCamera(camera);
recorder.setPreviewDisplay(surfaceHolder.getSurface());

recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);

File file = getAlbumDir();
recorder.setOutputFile(file.getAbsolutePath());

recorder.setMaxDuration(50000);
recorder.setMaxFileSize(5000000);
try {
    recorder.prepare();
    recorder.start();
} catch (IllegalStateException | IOException e) {
    e.printStackTrace();
}