Skip to content Skip to sidebar Skip to footer

Illegalstateexception With Mediarecorder.start() : Null

I'm trying to create a simple video recorder and here's my code in order that I'm calling it: protected boolean prepareForVideoRecording() { try { mCamera.unlock();

Solution 1:

I have written a lengthy article in my blog about problems like this. Summarizing it there are (at least to my knowledge) three methods to set up the Android mediarecorder and for each method I have had a device in my hands where this method did not work. So you need the user to try out which method works on his device. The methods are as follows:

  1. Use the devices default settings for video size, preview size etc., but set video size explicitly in the media recorder to the size of the preview that you get from the camera parameters after you have started the preview window but before you unlock the camera for recording.
  2. Use camcorder profiles like you did in your code. It should work flawlessly on most devices that have an Android version 4.0 and above. I would recommend to set maximum file size and video length though, but doubt that this is the problem with the Nexus 5. And I know at least one other device (Xperia ray upgraded to latest firmware version) where this does not work as well.
  3. Use one of the explicit video sizes that you get from getSupportedVideoSizes() from the camera parameters.

Method 1. and 3. require setting the output format, audio encoder and video encoder explicitly for which I always use MediaRecorder.OutputFormat.THREE_GPP , MediaRecorder.AudioEncoder.AMR_NB and MediaRecorder.VideoEncoder.MPEG_4_SP.

I have a small free app called Video Timer in Google Play which has implemented all three methods so you can try out easily what works on the Nexus 5.

Post a Comment for "Illegalstateexception With Mediarecorder.start() : Null"