Browse Source

Update README.md

main
蒋东国 7 years ago
committed by GitHub
parent
commit
606c9e5abe
  1. 83
      README.md

83
README.md

@ -1,32 +1,35 @@
# AndroidUSBCamera开源项目 # AndroidUSBCamera开源项目
##AndroidUSBCamera基于[saki4510t/UVCCamera](https://github.com/saki4510t/UVCCamera)开发,该项目对USB Camera(UVC设备)的使用和视频数据采集进行了高度封装,能够 ## AndroidUSBCamera基于[saki4510t/UVCCamera](https://github.com/saki4510t/UVCCamera)开发,该项目对USB Camera(UVC设备)的使用和视频数据采集进行了高度封装,能够帮助开发者通过几个简单的API实现USB Camera设备的检测、连接、预览和视频数据采集。主要功能包括:USB Camera实时预览;本地录制mp4格式视频;png格式图片抓拍;实时获取编码后的音视频数据流。
帮助开发者通过几个简单的API实现USB Camera设备的检测、连接、预览和视频数据采集。主要功能包括:USB Camera实时预览;本地录制mp4格式视频;png格式图片
抓拍;实时获取编码后的音视频数据流。
##如何使用AndroidUSBCamera项目 ## 如何使用AndroidUSBCamera项目
###1.添加依赖到本地工程 ### 1.添加依赖到本地工程
To get a Git project into your build: To get a Git project into your build:
第一步 添加JitPack仓库到工程gradle 第一步 添加JitPack仓库到工程gradle
Step 1. Add the JitPack repository to your build file Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories: Add it in your root build.gradle at the end of repositories:
` ```
allprojects { allprojects {
repositories { repositories {
... ...
maven { url 'https://jitpack.io' } maven { url 'https://jitpack.io' }
} }
} }
` ```
第二步 添加依赖到app Module的gradle
Step 2. Add the dependency 第二步 添加依赖到app Module的gradle
` Step 2. Add the dependency
```
dependencies { dependencies {
compile 'com.github.jiangdongguo:AndroidUSBCamera:v1.0.0' compile 'com.github.jiangdongguo:AndroidUSBCamera:v1.0.0'
} }
` ```
###2.初始化引擎,注册USB设备事件监听器
Init AndroidUSBCamera engine,register the USB device event listener ### 2.初始化引擎,注册USB设备事件监听器
` Init AndroidUSBCamera engine,register the USB device event listener
```
USBCameraManager mUSBManager = USBCameraManager.getInstance(); USBCameraManager mUSBManager = USBCameraManager.getInstance();
// mTextureView为UVCCameraTextureView实例,继承于TextureView // mTextureView为UVCCameraTextureView实例,继承于TextureView
// 用于渲染图像,需要在xml文件中定义 // 用于渲染图像,需要在xml文件中定义
@ -72,10 +75,11 @@ mUSBManager.init(this, mUVCCameraView, new USBCameraManager.OnMyDevConnectListen
} }
}); });
` ```
###3. 注册USB设备广播事件监听器,开始Camera预览
### 3. 注册USB设备广播事件监听器,开始Camera预览
Register the USB device broadcast event listener and start the Camera Preview Register the USB device broadcast event listener and start the Camera Preview
` ```
// 注册USB事件广播监听器 // 注册USB事件广播监听器
if(mUSBManager != null){ if(mUSBManager != null){
mUSBManager.registerUSB(); mUSBManager.registerUSB();
@ -84,10 +88,11 @@ if(mUSBManager != null){
if(mUVCCameraView != null){ if(mUVCCameraView != null){
mUVCCameraView.onResume(); mUVCCameraView.onResume();
} }
` ```
###4. 注销USB设备广播事件监听器,停止Camera预览
### 4. 注销USB设备广播事件监听器,停止Camera预览
Unregister the USB device broadcast event listener and stop the Camera Preview Unregister the USB device broadcast event listener and stop the Camera Preview
` ```
// 注销USB事件广播监听器 // 注销USB事件广播监听器
if(mUSBManager != null){ if(mUSBManager != null){
mUSBManager.unregisterUSB(); mUSBManager.unregisterUSB();
@ -96,19 +101,22 @@ if(mUSBManager != null){
if(mUVCCameraView != null){ if(mUVCCameraView != null){
mUVCCameraView.onPause(); mUVCCameraView.onPause();
} }
` ```
###5. 图片抓拍
### 5. 图片抓拍
Picture capturing Picture capturing
` ```
if(mUSBManager == null || ! mUSBManager.isCameraOpened()){ if(mUSBManager == null || ! mUSBManager.isCameraOpened()){
showShortMsg("抓拍异常,摄像头未开启"); showShortMsg("抓拍异常,摄像头未开启");
return; return;
} }
mUSBManager.capturePicture(picPath); mUSBManager.capturePicture(picPath);
` ```
###6. 本地录制(可实时获取音视频数据流)
recoring mp4,and get media real-stream ### 6. 本地录制(可实时获取音视频数据流)
` recoring mp4,and get media real-stream
```
if(mUSBManager == null || ! mUSBManager.isCameraOpened()){ if(mUSBManager == null || ! mUSBManager.isCameraOpened()){
showShortMsg("录制异常,摄像头未开启"); showShortMsg("录制异常,摄像头未开启");
return; return;
@ -123,21 +131,24 @@ mUSBManager.startRecording(videoPath, new AbstractUVCCameraHandler.OnEncodeResul
} }
// 停止录制 // 停止录制
mUSBManager.stopRecording(); mUSBManager.stopRecording();
` ```
###7. 释放引擎资源
release resource ### 7. 释放引擎资源
` release resource
```
// 释放资源 // 释放资源
if(mUSBManager != null){ if(mUSBManager != null){
mUSBManager.release(); mUSBManager.release();
} }
` ```
###USBCameraManager API (Other)
` ### USBCameraManager API (Other)
```
(1) void requestPermission(int index):请求授予开启USB摄像头权限; (1) void requestPermission(int index):请求授予开启USB摄像头权限;
(2) int getUsbDeviceCount():返回查询到的可用USB Camera数目; (2) int getUsbDeviceCount():返回查询到的可用USB Camera数目;
(3) boolean isRecording():判断是否正在录制视频; (3) boolean isRecording():判断是否正在录制视频;
(4) boolean isCameraOpened():判断USB摄像头是否正常打开; (4) boolean isCameraOpened():判断USB摄像头是否正常打开;
(5) void release():释放资源 (5) void release():释放资源
(6) USBMonitor getUSBMonitor():返回USBMonitor实例; (6) USBMonitor getUSBMonitor():返回USBMonitor实例;
` ```

Loading…
Cancel
Save