Recording Videos Simply 简单录制视频

Your application has a job to do, and integrating videos is only a small part of it. You want to take videos with minimal fuss, and not reinvent the camcorder. Happily, most Android-powered devices already have a camera application that records video. In this lesson, you make it do this for you.http://blog.youkuaiyun.com/sergeycao

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" />
    ...
</manifest ... >

If your application uses, but does not require a camera in order to function, add android:required="false" to the tag. In doing so, Google Play will allow devices without a camera to download your application. It's then your responsibility to check for the availability of 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 involves three pieces: the Intent 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.

private void dispatchTakeVideoIntent() {
    Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    startActivityForResult(takeVideoIntent, ACTION_TAKE_VIDEO);
}

It's a good idea to make sure an app exists to handle your intent before invoking it. Here's a function that checks for apps that can handle your intent:

public static boolean isIntentAvailable(Context context, String action) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    List<ResolveInfo> list =
        packageManager.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

View the Video

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

private void handleCameraVideo(Intent intent) {
    mVideoUri = intent.getData();
    mVideoView.setVideoURI(mVideoUri);
}
NatCorder是适用于iOS,Android,macOS和Windows的轻巧,易于使用的全功能视频录制API。使用NatCorder,您可以记录屏幕,特定的游戏摄像头,纹理,原始像素数据等。您还可以录制来自音频源,听众和自定义源的游戏音频。NatCorder经过高度优化,以较低的内存占用量实现速度。功能包括: - 快速燃烧。NatCorder是经过高度优化的性能。 - 记录任何东西!记录所有可以渲染到纹理中的东西。无论是游戏视图,UI,相机还是纹理,NatCorder都可以记录下来。 - 自定义分辨率。以高达全高清(1920x1080)的分辨率录制,甚至在支持它的设备上以更高的分辨率录制。 - 控制质量。通过指定记录比特率和关键帧间隔来优化文件大小或带宽的记录。 - 记录GIF。除了录制MP4视频外,NatCorder还可以在iOS,Android,macOS和Windows上录制GIF动画图像。 - 记录HEVC。NatCorder支持在Android,iOS,macOS和Windows上使用H.265 HEVC编解码器进行录制。 - AR支持。NatCorder完全支持Vuforia,ARCore和ARKit。 - 完全访问。NatCorder将直接记录到应用程序文档目录中,并提供视频的路径。 - 离线记录。NatCorder支持在for循环中进行记录。这对于转码应用程序特别有用。 - 线程记录。NatCorder是线程安全的,允许您在工作线程中进行记录以进一步提高性能。 - 轻巧的包装。该API专门设计为不会在您的项目中增加不必要的负担或开销。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值