我的代码设置MediaRecorder mMediaRecorder;
mMediaRecorder = new MediaRecorder();
// Step 1: Unlock and set camera to MediaRecorder
mCamera.stopPreview();
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
try {
if (Audio_source > -1)
mMediaRecorder.setAudioSource(Audio_source);
else
mMediaRecorder
.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
if (Video_source > -1)
mMediaRecorder.setVideoSource(Video_source);
else
mMediaRecorder
.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
if (Video_outputformat > -1)
mMediaRecorder.setOutputFormat(Video_outputformat);
else
mMediaRecorder
.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
if (Video_encorder > -1)
mMediaRecorder.setVideoEncoder(Video_encorder);
else
mMediaRecorder
.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
if (Video_framerate > -1) {
mMediaRecorder.setVideoFrameRate(Video_framerate);
}
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
mMediaRecorder.setProfile(CamcorderProfile
.get(CamcorderProfile.QUALITY_LOW));
catch (Exception e) {
// TODO: handle exception
E022.saveErrorLog(e.getMessage(), context);
}
目标值:
Audio_source = -1, Video_source = -1, Video_outputformat = -1,
Video_encorder = -1, Video_framerate = -1
例如:
03-12 14:54:12.937: W/System.err(11577): java.lang.IllegalStateException
03-12 14:54:12.938: W/System.err(11577): at android.media.MediaRecorder.setOutputFormat(Native Method)
03-12 14:54:12.940: W/System.err(11577): at android.media.MediaRecorder.setProfile(MediaRecorder.java:366)
03-12 14:54:12.942: W/System.err(11577): at jp.osaka.ECAMERA.prepareVideoRecorder(ECAMERA.java:1300)
03-12 14:54:12.945: W/System.err(11577): at jp.osaka.ECAMERA.access$16(ECAMERA.java:1259)
03-12 14:54:12.947: W/System.err(11577): at jp.osaka.ECAMERA$6.onClick(ECAMERA.java:347)
03-12 14:54:12.948: W/System.err(11577): at android.view.View.performClick(View.java:3517)
03-12 14:54:12.950: W/System.err(11577): at android.view.View$PerformClick.run(View.java:14155)
03-12 14:54:12.952: W/System.err(11577): at android.os.Handler.handleCallback(Handler.java:605)
03-12 14:54:12.954: W/System.err(11577): at android.os.Handler.dispatchMessage(Handler.java:92)
03-12 14:54:12.956: W/System.err(11577): at android.os.Looper.loop(Looper.java:137)
03-12 14:54:12.957: W/System.err(11577): at android.app.ActivityThread.main(ActivityThread.java:4503)
03-12 14:54:12.958: W/System.err(11577): at java.lang.reflect.Method.invokeNative(Native Method)
03-12 14:54:12.959: W/System.err(11577): at java.lang.reflect.Method.invoke(Method.java:511)
03-12 14:54:12.961: W/System.err(11577): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
03-12 14:54:12.963: W/System.err(11577): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
03-12 14:54:12.965: W/System.err(11577): at dalvik.system.NativeStart.main(Native Method)
为什么会发生异常java.lang.IllegalStateException
? (我在android手机4.0上测试)