【问题标题】:Intent to take video in android打算在android中拍摄视频
【发布时间】:2014-01-29 18:54:48
【问题描述】:

我需要仅使用前置摄像头从我的应用程序中拍摄视频。我正在使用意图来执行此操作。

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);

当我运行应用程序时,我可以使用前置摄像头拍摄视频。但是假设当我单击我的录制视频按钮并打开相机视图时。在那个用户中,将摄像头更改为后置摄像头,然后我的意图总是在那之后才打开后置摄像头。它不走线

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

有人可以告诉我是什么问题吗?是否可以使用意图来解决?

【问题讨论】:

  • 有意设置这个,并不适用于所有设备。
  • 但它是第一次工作..即使我的摄像头设置是后置摄像头..
  • 查看此链接,它可能会对您有所帮助-stackoverflow.com/questions/19667094/…
  • 我没有为这个问题找到合适的解决方案。使用相机预览我总是能够打开前置摄像头。但通过意图我不是。所以我仍然不确定是否有任何其他有意图的解决方法。

标签: android video android-intent camera video-capture


【解决方案1】:

没有可靠的方法来使用意图始终显示前置摄像头,至少不是在所有设备上。唯一可靠的方法是创建一个 SurfaceView 并自己捕获视频。

【讨论】:

    【解决方案2】:

    看看这是否有效:

    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();
    
    }
    

    来源:Front camera in android

    如果视频开始在后置摄像头上录制,您可以使用 Android keyEvents 触发摄像头开关的按钮按下。 KeyEvents 需要完美计时,否则它们最终会触发其他东西!检查:KeyEvent.

    如果你正在使用

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

    CamcorderProfile.get() 的此签名默认为后置摄像头的配置文件。 因此,不要使用它,而是使用:

    public static CamcorderProfile get (int cameraId, int quality)
    
    mediaRecorder.setVideoFrameRate(15);
    

    使用任何值,1 - 15 表示帧速率。 查看this了解更多详情。

    希望这会有所帮助。

    【讨论】:

      【解决方案3】:

      创建您的自定义视频拍摄应用程序,确保仅使用前置摄像头

      我认为这是唯一的方法。

      希望有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多