AndroidUSBCamera
============
AndroidUSBCamera is developed based on the [saki4510t/UVCCamera](https://github.com/saki4510t/UVCCamera), the project of USB Camera (UVC equipment) and the use of video data acquisition are highly packaged, and it can help developers using USB Camera devices easily by a few simple APIs. By using AndroidUSBCamera,you can detect and connect to a USB Camera simply.And you also can use it to realize taking picture,recording mp4,switching resolutions ,getting h.264/aac/yuv(nv21) stream and setting camera's contrast or brightness,supporting 480P、720P、1080P and higher,etc.
[中文文档: AndroidUSBCamera,UVCCamera开发通用库](http://blog.csdn.net/andrexpert/article/details/78324181)
Usage
-------
### 1.Add to your Android Studio project
Step 1. Add the JitPack repository to your build file.Add it in your root build.gradle at the end of repositories:
```java
allprojects {
repositories {
...
maven { url 'http://raw.github.com/saki4510t/libcommon/master/repository/' }
maven { url 'https://jitpack.io' }
}
}
```
Step 2. Add the dependency
```java
dependencies {
implementation 'com.github.jiangdongguo:AndroidUSBCamera:2.2.8'
}
```
### 2. APIs Introduction
(1) In order to using it correctly,the following four steps must be achieved:
```java
mUVCCameraView = (CameraViewInterface) mTextureView;
mUVCCameraView.setCallback(mCallback);
mCameraHelper = UVCCameraHelper.getInstance();
// set default preview size
mCameraHelper.setDefaultPreviewSize(1280,720);
// set default frame format,defalut is UVCCameraHelper.Frame_FORMAT_MPEG
// if using mpeg can not record mp4,please try yuv
// mCameraHelper.setDefaultFrameFormat(UVCCameraHelper.FRAME_FORMAT_YUYV);
mCameraHelper.initUSBMonitor(this, mUVCCameraView, mDevConnectListener);
```
To be attention,mCallback is a object of interface CameraViewInterface.Callback,and it's used to be listenering surfaceView
created or detoryed.mDevConnectListener is a object of interface UVCCameraHelper.OnMyDevConnectListener,and it's used to be listenering to detect and conntect USB device.Here is the coding order:
```java
private CameraViewInterface.Callback mCallback = new CameraViewInterface.Callback mCallback(){
@Override
public void onSurfaceCreated(CameraViewInterface view, Surface surface) {
// must have
if (!isPreview && mCameraHelper.isCameraOpened()) {
mCameraHelper.startPreview(mUVCCameraView);
isPreview = true;
}
}
@Override
public void onSurfaceChanged(CameraViewInterface view, Surface surface, int width, int height) {
}
@Override
public void onSurfaceDestroy(CameraViewInterface view, Surface surface) {
// must have
if (isPreview && mCameraHelper.isCameraOpened()) {
mCameraHelper.stopPreview();
isPreview = false;
}
}
}
private UVCCameraHelper.OnMyDevConnectListener listener = new UVCCameraHelper.OnMyDevConnectListener() {
@Override
public void onAttachDev(UsbDevice device) {
// request open permission(must have)
if (!isRequest) {
isRequest = true;
if (mCameraHelper != null) {
mCameraHelper.requestPermission(0);
}
}
}
@Override
public void onDettachDev(UsbDevice device) {
// close camera(must have)
if (isRequest) {
isRequest = false;
mCameraHelper.closeCamera();
}
}
@Override
public void onConnectDev(UsbDevice device, boolean isConnected) {
}
@Override
public void onDisConnectDev(UsbDevice device) {
}
};
```
![Connecting gif](https://github.com/jiangdongguo/AndroidUSBCamera/blob/master/gifs/detecting.gif)
(2) Capturing JPG Images
```java
mCameraHelper.capturePicture(picPath, new AbstractUVCCameraHandler.OnCaptureListener() {
@Override
public void onCaptureResult(String path) {
Log.i(TAG,"save path:" + path);
}
});
```
(3) Recording Mp4,supporting close voice and save file automatic.
```java
RecordParams params = new RecordParams();
params.setRecordPath(videoPath);
params.setRecordDuration(0); // 0,do not cut save
params.setVoiceClose(mSwitchVoice.isChecked()); // is close voice
mCameraHelper.startPusher(params, new AbstractUVCCameraHandler.OnEncodeResultListener() {
@Override
public void onEncodeResult(byte[] data, int offset, int length, long timestamp, int type) {
// type = 1,h264 video stream
if (type == 1) {
// FileUtils.putFileStream(data, offset, length);
}
// type = 0,aac audio stream
if(type == 0) {
}
}
@Override
public void onRecordResult(String videoPath) {
Log.i(TAG,"videoPath = "+videoPath);
}
});
// of course,if you only want to getting h.264 and aac stream
// you can do like this
mCameraHelper.startPusher(listener);
```
(4) setting camera's brightness and contrast.
```java
mCameraHelper.setModelValue(UVCCameraHelper.MODE_BRIGHTNESS,progress);
mCameraHelper.setModelValue(UVCCameraHelper.MODE_CONTRAST,progress);
mCameraHelper.getModelValue(UVCCameraHelper.MODE_BRIGHTNESS);
mCameraHelper.getModelValue(UVCCameraHelper.MODE_CONTRAST);
...
```
![Connecting gif](https://github.com/jiangdongguo/AndroidUSBCamera/blob/master/gifs/brightness.gif)
(5) switch resolutions and camera.
```java
mCameraHelper.updateResolution(widht, height);
```
![Connecting gif](https://github.com/jiangdongguo/AndroidUSBCamera/blob/master/gifs/2.1.0.gif)
At last,remember adding permissions:
```
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
```
Other Library about Android Camera
-------
[OkCamera](https://github.com/jiangdongguo/OkCamera) Android Camera univsersally operation.
[AndroidRecordMp4](https://github.com/jiangdongguo/AndroidRecordMp4) Using MediaCodec realize record mp4.
[AndroidYuvOsd](https://github.com/jiangdongguo/AndroidYuvOsd) YUV data operation.
[Lame4Mp3](https://github.com/jiangdongguo/Lame4Mp3) pcm to mp3 and pcm to aac.
License
-------
Copyright 2018 Jiangdongguo
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
没有合适的资源?快使用搜索试试~ 我知道了~
Android USBCamera,通过UVCCamera开发通用库
共3940个文件
flat:1770个
class:772个
xml:423个
需积分: 47 56 下载量 81 浏览量
2018-12-29
09:22:20
上传
评论 2
收藏 49.83MB RAR 举报
温馨提示
Android USBCamera,UVCCamera开发通用库 https://blog.csdn.net/qq_31939617/article/details/82347939
资源推荐
资源详情
资源评论
收起资源包目录
Android USBCamera,通过UVCCamera开发通用库 (3940个子文件)
+QTHly_pJ1mVmsCat5vkJ8l1JS0= 661KB
+QTHly_pJ1mVmsCat5vkJ8l1JS0= 661KB
1zQs5ZnrxmrI34NkYX0DjLkbkU8= 163KB
1zQs5ZnrxmrI34NkYX0DjLkbkU8= 163KB
2KM4k4aqYm6jKA2Popn2CyYlNJY= 755KB
2KM4k4aqYm6jKA2Popn2CyYlNJY= 755KB
4xvnrQy7zkLFxYZZodEHB_aep2I= 102KB
4xvnrQy7zkLFxYZZodEHB_aep2I= 102KB
8k4zCxR2QG2vRi0rh1CA0Jz5dyM= 316KB
8k4zCxR2QG2vRi0rh1CA0Jz5dyM= 316KB
_7aA0fge5mOyryRojjdXLmMRZ1I= 39KB
_7aA0fge5mOyryRojjdXLmMRZ1I= 39KB
resources-debugAndroidTest.ap_ 755KB
resources-debugAndroidTest.ap_ 755KB
resources-debug.ap_ 667KB
resources-debug.ir.ap_ 658KB
app-debug.apk 3.1MB
dependencies.apk 1.26MB
slice_8.apk 76KB
slice_0.apk 70KB
slice_1.apk 61KB
slice_7.apk 48KB
slice_2.apk 45KB
slice_4.apk 10KB
slice_5.apk 9KB
slice_3.apk 4KB
slice_6.apk 3KB
slice_9.apk 3KB
gradlew.bat 2KB
fileSnapshots.bin 2.47MB
classAnalysis.bin 1.06MB
classAnalysis.bin 1.06MB
taskHistory.bin 723KB
jarAnalysis.bin 456KB
jarAnalysis.bin 456KB
fileHashes.bin 206KB
taskHistory.bin 122KB
taskHistory.bin 117KB
taskHistory.bin 110KB
fileHashes.bin 75KB
taskJars.bin 22KB
taskJars.bin 22KB
outputFiles.bin 21KB
resourceHashesCache.bin 20KB
resourceHashesCache.bin 19KB
last-build.bin 1B
last-build.bin 1B
bL8feD64dBX3Op3SUUNJSW1x4Ag= 258KB
bL8feD64dBX3Op3SUUNJSW1x4Ag= 258KB
USBCameraActivity.class 48KB
USBCameraActivity.class 48KB
UVCCameraTextureView.class 47KB
UVCCameraTextureView.class 47KB
AspectRatioTextureView.class 43KB
AspectRatioTextureView.class 43KB
USBVendorId.class 41KB
USBVendorId.class 41KB
USBVendorId.class 39KB
USBVendorId.class 39KB
USBVendorId.class 39KB
UVCCamera.class 37KB
UVCCamera.class 37KB
R$color.class 30KB
USBMonitor.class 30KB
USBMonitor.class 30KB
AbstractUVCCameraHandler$CameraThread.class 29KB
AbstractUVCCameraHandler$CameraThread.class 29KB
UVCCamera.class 29KB
UVCCamera.class 29KB
UVCCamera.class 29KB
R$styleable.class 28KB
R$style.class 26KB
R$style.class 26KB
R$styleable.class 25KB
R$styleable.class 25KB
R$styleable.class 25KB
R$styleable.class 25KB
R$styleable.class 25KB
R$styleable.class 25KB
R$styleable.class 25KB
R$styleable.class 25KB
R$color.class 25KB
R$styleable.class 25KB
R$color.class 23KB
R$color.class 23KB
R$color.class 23KB
R$color.class 23KB
R$color.class 23KB
R$color.class 23KB
R$color.class 23KB
R$color.class 23KB
USBMonitor.class 23KB
USBMonitor.class 23KB
USBMonitor.class 23KB
R$styleable.class 22KB
R$styleable.class 22KB
R$styleable.class 22KB
R$styleable.class 22KB
R$style.class 22KB
R$style.class 22KB
共 3940 条
- 1
- 2
- 3
- 4
- 5
- 6
- 40
资源评论
卷小毛丶
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功