capacitor-plugin-camera-forked 3.0.94 → 3.0.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -350,8 +350,12 @@ public class CameraPreviewPlugin extends Plugin {
350
350
  return;
351
351
  }
352
352
  if (useCaseGroup == null) {
353
- call.reject("Camera use cases not initialized");
354
- return;
353
+ // Re-initialize use cases if they were cleared
354
+ setupUseCases(false);
355
+ if (useCaseGroup == null) {
356
+ call.reject("Camera use cases not initialized");
357
+ return;
358
+ }
355
359
  }
356
360
  if (previewView == null) {
357
361
  call.reject("Preview view not initialized");
@@ -412,9 +416,22 @@ public class CameraPreviewPlugin extends Plugin {
412
416
  public void run() {
413
417
  try {
414
418
  restoreWebViewBackground();
415
- previewView.setVisibility(View.INVISIBLE);
416
- previewView.setBackgroundColor(Color.BLACK);
417
- cameraProvider.unbindAll();
419
+ if (previewView != null) {
420
+ previewView.setVisibility(View.INVISIBLE);
421
+ previewView.setBackgroundColor(Color.BLACK);
422
+ }
423
+ if (cameraProvider != null) {
424
+ cameraProvider.unbindAll();
425
+ }
426
+ // Null out references to help GC and ensure release
427
+ camera = null;
428
+ imageCapture = null;
429
+ preview = null;
430
+ imageAnalysis = null;
431
+ useCaseGroup = null;
432
+ recorder = null;
433
+ currentRecording = null;
434
+ Log.d("Camera", "Camera stopped and all references cleared.");
418
435
  call.resolve();
419
436
  } catch (Exception e) {
420
437
  call.reject(e.getMessage());
@@ -1222,12 +1239,21 @@ public class CameraPreviewPlugin extends Plugin {
1222
1239
 
1223
1240
  @Override
1224
1241
  protected void handleOnPause() {
1225
- if (camera != null) {
1242
+ if (camera != null && cameraProvider != null) {
1226
1243
  CameraState cameraStatus = camera.getCameraInfo().getCameraState().getValue();
1227
1244
  previousCameraStatus = cameraStatus;
1228
1245
  if (cameraStatus.getType() == CameraState.Type.OPEN) {
1229
1246
  cameraProvider.unbindAll();
1230
1247
  }
1248
+ // Null out references
1249
+ camera = null;
1250
+ imageCapture = null;
1251
+ preview = null;
1252
+ imageAnalysis = null;
1253
+ useCaseGroup = null;
1254
+ recorder = null;
1255
+ currentRecording = null;
1256
+ Log.d("Camera", "handleOnPause: Camera stopped and references cleared.");
1231
1257
  }
1232
1258
  super.handleOnPause();
1233
1259
  }
@@ -1306,4 +1332,4 @@ public class CameraPreviewPlugin extends Plugin {
1306
1332
  call.resolve(result);
1307
1333
  }
1308
1334
 
1309
- }
1335
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-plugin-camera-forked",
3
- "version": "3.0.94",
3
+ "version": "3.0.95",
4
4
  "description": "A capacitor camera plugin - A custom Capacitor camera plugin with additional features.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",