简单的安卓video recording 以及实时播放(来自:https://developer.android.com/training/camera/videobasics.html#TaskV)

Request Camera Permission


To advertise that your application depends on having a camera, put a<uses-feature> tag in the manifest file:

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

If your application uses, but does not require a camera in order to function, set android:required to false. In doing so, Google Play will allow devices without acamera to download your application. It's then your responsibility to check for the availabilityof the camera at runtime by calling hasSystemFeature(PackageManager.FEATURE_CAMERA).If a camera is not available, you should then disable your camera features.

Record a Video with a Camera App


The Android way of delegating actions to other applications is to invoke an Intent that describes what you want done. This process involves three pieces: TheIntent itself, a call to start the external Activity,and some code to handle the video when focus returns to your activity.

Here's a function that invokes an intent to capture video.

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

Notice that the startActivityForResult() method is protected by a condition that callsresolveActivity(), which returns thefirst activity component that can handle the intent. Performing this checkis important because if you call startActivityForResult() using an intent that no app can handle,your app will crash. So as long as the result is not null, it's safe to use the intent.

View the Video


The Android Camera application returns the video in the Intent deliveredto onActivityResult() as a Uri pointing to the video location in storage. The following coderetrieves this video and displays it in a VideoView.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
        Uri videoUri = intent.getData();
        mVideoView.setVideoURI(videoUri);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值