【开源】LandscapeVideoCamera

LandscapeVideoCamera

  •  https://github.com/jmolsmobile/LandscapeVideoCamera

    介绍:

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

    运行效果:

    非常强大的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
    2
    3
    4
    <activity
        android:name="com.jmolsmobile.landscapevideocapture.VideoCaptureActivity"
        android:screenOrientation="sensor" >
    </activity>

     

    在manifest中添加如下权限:

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

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

    1
    2
    3
    4
    Capture configuration = CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality);
    Capture configuration = CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality, int maxDurationSecs, int maxFilesizeMb);
    Capture configuration = CaptureConfiguration(int videoWidth, int videoHeight, int bitrate);
    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
    2
    3
    4
    final Intent intent = new Intent(getActivity(), VideoCaptureActivity.class);
    intent.putExtra(VideoCaptureActivity.EXTRA_CAPTURE_CONFIGURATION, config);
    intent.putExtra(VideoCaptureActivity.EXTRA_OUTPUT_FILENAME, filename);
    startActivityForResult(intent, RESULT_CODE);

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

posted on 2015-04-03 10:25  wasdchenhao  阅读(330)  评论(0)    收藏  举报

导航