zoukankan      html  css  js  c++  java
  • 【转】开源视频录制库LandscapeVideoCamera

    非常强大的android 视频录制库,可以选择视频尺寸以及视频质量,只允许横屏录制。

    使用Android自带的Camera应用可以录制视频,只需发送MediaStore.ACTION_VIDEO_CAPTURE的intent即可,但是有一些缺陷:

    内置应用intent的视频质量参数只允许为0和1 分别代表最低质量和最高质量,这个参数是一个extra 参数:MediaStore.EXTRA_VIDEO_QUALITY

    在指定了文件名的情况下,内置应用intent不会返回录制完视频的URI

    内置应用intent不关心用户录制的视频是横屏还是竖屏的。

    截图

    LandscapeVideoCamera的特点

    LandscapeVideoCamera提供了完整的可复用的自定义camera,有如下特点:

    (1)强制用户横屏录制(当为竖屏的时候是不能录制的)

    (2)允许指定录制视频的文件名,当然也支持自动生成文件名。

    (3)允许改变如下设置:

       分辨率

       码率

       视频文件最大占用空间

       视频录制时间

    使用

    将LandscapeVideoCamera库添加进你的项目中

    在manifest中添加VideoCaptureActivity :

    1 <activity
    2     android:name="com.jmolsmobile.landscapevideocapture.VideoCaptureActivity"
    3     android:screenOrientation="sensor" >
    4 </activity>

    在manifest中添加如下权限:

    1 <uses-permission android:name="android.permission.RECORD_AUDIO" />
    2 <uses-permission android:name="android.permission.CAMERA" />
    3 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     

    设置录制参数,创建CaptureConfiguration对象,根据需要选择合适的构造方法,有如下构造方法:

    1 Capture configuration = CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality);
    2 Capture configuration = CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality, int maxDurationSecs, int maxFilesizeMb);
    3 Capture configuration = CaptureConfiguration(int videoWidth, int videoHeight, int bitrate);
    4 Capture configuration = CaptureConfiguration(int videoWidth, int videoHeight, int bitrate, int maxDurationSecs, int maxFilesizeMb);
     

    如果没有设置CaptureConfiguration 则会使用默认的设置。

    用 startActivityForResult调用VideoCaptureActivity,CaptureConfiguration 作为parcelable类型参数EXTRA_CAPTURE_CONFIGURATION传递,文件名作为String类型参数 EXTRA_OUTPUT_FILENAME传递。

    1 final Intent intent = new Intent(getActivity(), VideoCaptureActivity.class);
    2 intent.putExtra(VideoCaptureActivity.EXTRA_CAPTURE_CONFIGURATION, config);
    3 intent.putExtra(VideoCaptureActivity.EXTRA_OUTPUT_FILENAME, filename);
    4 startActivityForResult(intent, RESULT_CODE);
     

    检查resultcode (RESULT_OK, RESULT_CANCELLED或者VideoCaptureActivity.RESULT_ERROR) ,如果成功则从intent extra 的EXTRA_OUTPUT_FILENAME中得到文件名。

    项目地址:http://jcodecraeer.com/a/opensource/2014/1213/2156.html

  • 相关阅读:
    集群项目总结和思考
    centos7安装zabbix
    string方法中字符与Unicode编码的相互转化:fromCharCode(),charCodeAt()
    element-ui @change添加自定义参数
    js ES6字符串的新功能
    js 去除字符串中的空格
    五月份,是金色的
    夏天快要到来了,2019年还有一半多的时间
    自定义element-ui中的图标
    js下拉框:从数组中筛选出匹配的数据
  • 原文地址:https://www.cnblogs.com/liangstudyhome/p/4168434.html
Copyright © 2011-2022 走看看