Recording a video in android app
<p>I am developing an application in which we have a customize camera recorder to record a video. It is default recorded in 3GP format when we didn't set the OutputFormat to MPEG4, but when we set the OUTPUTFOrmat to MPEG-4 which is also supported on iPhone then it gets FORCE Close as <code>illegalStateException</code>. Please help me regarding the same.</p>

<p>Code:</p>

<pre><code>@TargetApi(9)
private boolean prepareMediaRecorder(){
    myCamera = getCameraInstance();
    mediaRecorder = new MediaRecorder();

    myCamera.unlock();
    mediaRecorder.setCamera(myCamera);
    mediaRecorder.setOrientationHint(90);
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
mediaRecorder.setMaxFileSize(5000000); // Set max file size 5M
mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());
    try {
        mediaRecorder.prepare();
    } catch (IllegalStateException e) {
        releaseMediaRecorder();
        return false;
    } catch (IOException e) {
        releaseMediaRecorder();
        return false;
    }
    return true;

}
</code></pre>

<p><strong>Error:</strong></p>

<pre><code>09-05 01:26:37.720: E/AndroidRuntime(12073): FATAL EXCEPTION: main
09-05 01:26:37.720: E/AndroidRuntime(12073): java.lang.IllegalStateException
09-05 01:26:37.720: E/AndroidRuntime(12073):    at android.media.MediaRecorder.setOutputFormat(Native Method)
09-05 01:26:37.720: E/AndroidRuntime(12073):    at com.irant.cameraApplication.Videocapture.prepareMediaRecorder(Videocapture.java:161)
09-05 01:26:37.720: E/AndroidRuntime(12073):    at com.irant.cameraApplication.Videocapture.onClick(Videocapture.java:306)
09-05 01:26:37.720: E/AndroidRuntime(12073):    at android.view.View.performClick(View.java:2582)
09-05 01:26:37.720: E/AndroidRuntime(12073):    at android.view.View$PerformClick.run(View.java:9252)
09-05 01:26:37.720: E/AndroidRuntime(12073):    at android.os.Handler.handleCallback(Handler.java:587)
09-05 01:26:37.720: E/AndroidRuntime(12073):    at android.os.Handler.dispatchMessage(Handler.java:92)
09-05 01:26:37.720: E/AndroidRuntime(12073):    at android.os.Looper.loop(Looper.java:130)
09-05 01:26:37.720: E/AndroidRuntime(12073):    at android.app.ActivityThread.main(ActivityThread.java:3691)
09-05 01:26:37.720: E/AndroidRuntime(12073):    at java.lang.reflect.Method.invokeNative(Native Method)
09-05 01:26:37.720: E/AndroidRuntime(12073):    at java.lang.reflect.Method.invoke(Method.java:507)
09-05 01:26:37.720: E/AndroidRuntime(12073):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
09-05 01:26:37.720: E/AndroidRuntime(12073):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
09-05 01:26:37.720: E/AndroidRuntime(12073):    at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>Thanks in advance.</p>
