diff --git a/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java b/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java index ec85d76..1f28e2d 100644 --- a/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java +++ b/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java @@ -89,15 +89,15 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog if(! isConnected) { showShortMsg("连接失败,请检查分辨率参数是否正确"); } + showShortMsg("连接成功"); } // 与USB设备断开连接 @Override public void onDisConnectDev(UsbDevice device) { - + showShortMsg("连接失败"); } }; - private FileOutputStream fos; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { diff --git a/libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java b/libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java index d5c845a..9c72938 100644 --- a/libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java +++ b/libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java @@ -91,6 +91,8 @@ public class USBCameraManager{ if(listener != null){ listener.onDettachDev(device); } + // 释放资源 + release(); } // 当连接到USB Camera时,被回调 @@ -116,8 +118,6 @@ public class USBCameraManager{ if(listener != null){ listener.onDisConnectDev(device); } - // 关闭摄像头 - closeCamera(); } @Override @@ -131,9 +131,12 @@ public class USBCameraManager{ // 切换分辨率 public void updateResolution(Activity activity, CameraViewInterface cameraView, int width, int height, final OnPreviewListener mPreviewListener){ + // 如果分辨率无变化,则无需重启Camera + if(previewWidth == width && previewHeight == height){ + return; + } this.previewWidth = width; this.previewHeight = height; - // 关闭摄像头 closeCamera(); // 释放CameraHandler占用的相关资源