Android開源視頻錄制庫:LandscapeVideoCamera

jopen 9年前發布 | 110K 次閱讀 Android開發 移動開發 LandscapeVideoCamera

非常強大的android 視頻錄制庫,可以選擇視頻尺寸以及視頻質量,只允許橫屏錄制。

使用Android自帶的Camera應用可以錄制視頻,只需發送MediaStore.ACTION_VIDEO_CAPTURE的intent即可,但是有一些缺陷:

內置應用intent的視頻質量參數只允許為0和1 分別代表最低質量和最高質量,這個參數是一個extra 參數:MediaStore.EXTRA_VIDEO_QUALITY

在指定了文件名的情況下,內置應用intent不會返回錄制完視頻的URI

內置應用intent不關心用戶錄制的視頻是橫屏還是豎屏的。

截圖

Android開源視頻錄制庫:LandscapeVideoCamera

Android開源視頻錄制庫:LandscapeVideoCamera

Android開源視頻錄制庫:LandscapeVideoCamera

Android開源視頻錄制庫:LandscapeVideoCamera

LandscapeVideoCamera的特點

LandscapeVideoCamera提供了完整的可復用的自定義camera,有如下特點:

(1)強制用戶橫屏錄制(當為豎屏的時候是不能錄制的)

(2)允許指定錄制視頻的文件名,當然也支持自動生成文件名。

(3)允許改變如下設置:

   分辨率

   碼率

   視頻文件最大占用空間

   視頻錄制時間

使用

將LandscapeVideoCamera庫添加進你的項目中

在manifest中添加VideoCaptureActivity :

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


在manifest中添加如下權限:

<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對象,根據需要選擇合適的構造方法,有如下構造方法:

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傳遞。

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中得到文件名。

https://github.com/jmolsmobile/LandscapeVideoCamera


 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!