7

I need to take video from my application using only front camera. I am using intent to perform this action.

Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
intent.putExtra("android.intent.extra.durationLimit", 30);
intent.putExtra("android.intent.extras.CAMERA_FACING", 1); //to open front facing camera
startActivityForResult(intent, VIDEO_CAPTURE);

When I run the application, I am able to take video using front camera. But suppose when I click my record video button and the camera view is opened. In that user go and change the camera to rear camera, then always my intent is opening rear camera only after that. Its not taking the line

intent.putExtra("android.intent.extras.CAMERA_FACING", 1);

Could someone please tell me whats the issue and is it able to be solved using intent?

Anju
  • 9,379
  • 14
  • 55
  • 94
  • 1
    setting this in intent, is not going to work for every device. – amit singh Jan 18 '14 at 09:50
  • but its working for the first time..even though my camera settings was rear camera.. – Anju Jan 18 '14 at 09:57
  • 1
    check this link, it may help you- http://stackoverflow.com/questions/19667094/intent-does-not-set-the-camera-parameters – amit singh Jan 18 '14 at 10:08
  • I didn't get a proper solution for this question. Using Camera Preview I was able to open front camera always. But through intent I wasn't. So still I am not sure whether there is any other workaround with intent. – Anju Jan 30 '14 at 09:09

3 Answers3

3

There is no reliable way to use intent to show the front camera all the time at least not on all devices. Only way to reliably do it is to create a SurfaceView and capture the video yourself.

Aswin Rajendiran
  • 3,399
  • 1
  • 21
  • 18
2

See if this works :

try {
    if (Camera.getNumberOfCameras() == 2) {
        if (frontCamera) {
            frontCamera = false;
            prCamera.stopPreview();
            prMediaRecorder.release();
            prMediaRecorder = null;
            prCamera.release();
            prCamera = null;
        } else {

            frontCamera = true;
            prCamera.stopPreview();
            prMediaRecorder.release();
            prMediaRecorder = null;
            prCamera.release();
            prCamera = null;
        }
        Intent intent = new Intent(VideoCapture_New.this,
                VideoCapture_New.class);
        startActivity(intent);
    } else {
        Toast.makeText(VideoCapture_New.this,
                "Your device doesn't contain Front Camera.",
                Toast.LENGTH_SHORT).show();
    }
} catch (Exception e) {
    e.printStackTrace();
    Toast.makeText(VideoCapture_New.this,
            "Your device is not compatible for Front Camera.",
            Toast.LENGTH_SHORT).show();

}

source : Front camera in android

Else you could use Android keyEvents to trigger the button press of camera switch if video starts to record on back camera. KeyEvents need to timed perfectly otherwise they end triggering something else! Check : KeyEvent.

Also if you are making use of

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

This signature for CamcorderProfile.get() defaults to a profile for the back-facing camera. So instead of using this, use :

public static CamcorderProfile get (int cameraId, int quality)

mediaRecorder.setVideoFrameRate(15);

use any value, 1 - 15 for frame rate. check this for additional details.

Hope this helps.

Community
  • 1
  • 1
Ab5
  • 606
  • 9
  • 25
1

Create your custom video taking application that assure to only use the Front camera

i think this is the only way to do this .

Hope that Helps .