2

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
upward unkaind
  • 113
  • 1
  • 11

2 Answers2

0

Would you add the permission for accessing camera? Please check it. Refer following links. link link

Community
  • 1
  • 1
  • @upwardunkaind, Sorry. I am not think you like a way you said. Sometimes, we might miss the small things. Sorry again for this. – Keerthi Keyan Mar 02 '17 at 12:22
0

You need to remove below because by setting profile to mediarecorder will do the same

mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

Remove above two line below willl do the same

mMediaRecorder.setProfile((CamcorderProfile.get(CamcorderProfile.QUALITY_QVGA)));

Or if media recorder parameters are not setting by using setProfile thn maintain below sequence and try

CamcorderProfile profile =CamcorderProfile.get(CamcorderProfile.QUALITY_QVGA);

mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoSize(640,480); /// video size make dynamic based on the requirement or view size
mMediaRecorder.setVideoFrameRate(profile.videoFrameRate); /// from profile
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

Let me know if anything.

user1140237
  • 5,015
  • 1
  • 28
  • 56