Android 使用系统录制视频功能

第一步:

在清单文件中添加 <uses-feature> 代码:

  <manifest ... >
        <uses-feature android:name="android.hardware.camera"
                      android:required="true" />
        ...
    </manifest>

第二步:

调用 Intent 以拍摄视频的函数

 static final int REQUEST_VIDEO_CAPTURE = 1;

    private void dispatchTakeVideoIntent() {
        Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
        }
    }

第三步录制完成后,返回获取到视频的uri

  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
            Uri videoUri = intent.getData();
           
        }
    }
    

 

注意,记得动态申请权限:CAMERA和WRITE_EXTERNAL_STORAGE

 

posted on 2020-12-07 09:54  LoaderMan  阅读(1251)  评论(0编辑  收藏  举报

导航