Browse Source

支持边推流,边本地录制

main
jiangdongguo 7 years ago
parent
commit
d08f5c3ab1
  1. 4
      app/build.gradle
  2. 15
      app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java
  3. 2
      libusbcamera/build.gradle
  4. 1
      libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java

4
app/build.gradle

@ -5,7 +5,7 @@ android {
buildToolsVersion "26.0.1" buildToolsVersion "26.0.1"
defaultConfig { defaultConfig {
applicationId "com.jiangdg.usbcamera" applicationId "com.jiangdg.usbcamera"
minSdkVersion 18 minSdkVersion 16
targetSdkVersion 22 targetSdkVersion 22
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
@ -29,6 +29,4 @@ dependencies {
compile project(':libusbcamera') compile project(':libusbcamera')
compile 'com.jakewharton:butterknife:8.8.1' compile 'com.jakewharton:butterknife:8.8.1'
compile 'com.jakewharton:butterknife-compiler:8.8.1' compile 'com.jakewharton:butterknife-compiler:8.8.1'
compile 'com.jakewharton:butterknife:8.8.1'
compile 'com.jakewharton:butterknife-compiler:8.8.1'
} }

15
app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java

@ -47,15 +47,18 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog
private boolean isRequest; private boolean isRequest;
// USB设备监听器 /**
* USB设备事件监听器
* */
private USBCameraManager.OnMyDevConnectListener listener = new USBCameraManager.OnMyDevConnectListener() { private USBCameraManager.OnMyDevConnectListener listener = new USBCameraManager.OnMyDevConnectListener() {
// 插入USB设备
@Override @Override
public void onAttachDev(UsbDevice device) { public void onAttachDev(UsbDevice device) {
if(mUSBManager == null || mUSBManager.getUsbDeviceCount() == 0){ if(mUSBManager == null || mUSBManager.getUsbDeviceCount() == 0){
showShortMsg("未检测到USB摄像头设备"); showShortMsg("未检测到USB摄像头设备");
return; return;
} }
// 请求打开摄像头
if(! isRequest){ if(! isRequest){
isRequest = true; isRequest = true;
if(mUSBManager != null){ if(mUSBManager != null){
@ -64,23 +67,27 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog
} }
} }
// 拔出USB设备
@Override @Override
public void onDettachDev(UsbDevice device) { public void onDettachDev(UsbDevice device) {
if(isRequest){ if(isRequest){
// 关闭摄像头
isRequest = false; isRequest = false;
mUSBManager.closeCamera(); mUSBManager.closeCamera();
showShortMsg(device.getDeviceName()+"已拨出"); showShortMsg(device.getDeviceName()+"已拨出");
} }
} }
// 连接USB设备成功
@Override @Override
public void onConnectDev(UsbDevice device) { public void onConnectDev(UsbDevice device) {
// 处理连接到设备后的逻辑
} }
// 与USB设备断开连接
@Override @Override
public void onDisConnectDev(UsbDevice device) { public void onDisConnectDev(UsbDevice device) {
// 处理与设备断开后的逻辑
} }
}; };
private FileOutputStream fos; private FileOutputStream fos;

2
libusbcamera/build.gradle

@ -5,7 +5,7 @@ android {
buildToolsVersion "26.0.1" buildToolsVersion "26.0.1"
defaultConfig { defaultConfig {
minSdkVersion 18 minSdkVersion 16
targetSdkVersion 22 targetSdkVersion 22
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"

1
libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java

@ -7,7 +7,6 @@ import android.hardware.usb.UsbDevice;
import android.os.Environment; import android.os.Environment;
import com.jiangdg.libusbcamera.R; import com.jiangdg.libusbcamera.R;
import com.serenegiant.usb.CameraDialog;
import com.serenegiant.usb.DeviceFilter; import com.serenegiant.usb.DeviceFilter;
import com.serenegiant.usb.USBMonitor; import com.serenegiant.usb.USBMonitor;
import com.serenegiant.usb.common.AbstractUVCCameraHandler; import com.serenegiant.usb.common.AbstractUVCCameraHandler;

Loading…
Cancel
Save