I try to set
mMediaRecorder.setProfile((CamcorderProfile.get(CamcorderProfile.QUALITY_QVGA)));
when i started the camera services i see in log this error:
E/MediaRecorder: setOutputFormat called in an invalid state: 4
E/RecorderService: null ошибка
W/System.err: java.lang.IllegalStateException
W/System.err: at android.media.MediaRecorder.setOutputFormat(Native Method)
W/System.err: at android.media.MediaRecorder.setProfile(MediaRecorder.java:539)
W/System.err: at com.hidecamera.hideng.services_record.RecorderService.startRecording(RecorderService.java:193)
W/System.err: at com.hidecamera.hideng.services_record.RecorderService.onStartCommand(RecorderService.java:73)
W/System.err: at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4128)
W/System.err: at android.app.ActivityThread.access$2400(ActivityThread.java:229)
W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1924)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err: at android.os.Looper.loop(Looper.java:148)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7325)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
[ 03-02 12:53:47.295 13476:13476 E/ ]
Available MB : 2496291
if I remove the code the video recording starts but low quality
mServiceCamera.unlock();
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setCamera(mServiceCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
selectFolder(MainActivity.isHideFolder);
mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mMediaRecorder.setOrientationHint(CameraUtil.computePictureRotation());
mMediaRecorder.setProfile((CamcorderProfile.get(CamcorderProfile.QUALITY_QVGA)));
mMediaRecorder.prepare();
mMediaRecorder.start();
UPDATE:
public boolean startRecording() {
try {
Toast.makeText(getBaseContext(), "Recording Started", Toast.LENGTH_SHORT).show();
if (!MainActivity.currentCameraId) {
mServiceCamera = Camera.open(0);//CAMERA_FACING_BACK
Log.d(TAG, "CAMERA_FACING_BACK");
} else {
mServiceCamera = Camera.open(1);//CAMERA_FACING_FRONT
Log.d(TAG, "CAMERA_FACING_FRONT");
}
CamcorderProfile profile = CamcorderProfile.get(getqualityvideo(MainActivity.quality));
mServiceCamera.unlock();
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setCamera(mServiceCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
int width = profile.videoFrameWidth;
int height = profile.videoFrameHeight;
mMediaRecorder.setVideoSize(width, height);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
selectFolder(MainActivity.isHideFolder);//папка с видео
mMediaRecorder.setOrientationHint(CameraUtil.computePictureRotation());
mMediaRecorder.prepare();
mMediaRecorder.start();
mRecordingStatus = true;
return true;
} catch (IllegalStateException e) {
Log.e(TAG, e.getMessage() + " ошибка IllegalStateException");
return false;
} catch (IOException e) {
Log.e(TAG, e.getMessage() + " ошибка IOException");
return false;
} catch (NullPointerException e) {
Log.e(TAG, e.getMessage() + " ошибка NullPointerException");
return false;
} catch (Exception e) {
Log.e(TAG, e.getMessage() + " ошибка Exception");
return false;
}
}
after start record in logs i saw this:
03-04 00:03:33.073 23949-23949/com.joukehiden.camera E/MediaRecorder: start failed: -38
03-04 00:03:33.073 23949-23949/com.joukehiden.camera E/RecorderService: null ошибка IllegalStateException
[ 03-04 00:03:33.076 23949:23949 E/ ]
Available MB : 3052817