Intent to take video in android

浪尽此生 提交于 2020-01-01 09:29:05

问题


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?


回答1:


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.




回答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.




回答3:


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 .



来源:https://stackoverflow.com/questions/21202416/intent-to-take-video-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!