Skip to content

Commit

Permalink
resolve conflict move videoRecorder setup in setUp camera
Browse files Browse the repository at this point in the history
  • Loading branch information
YushraJewon committed May 27, 2024
1 parent 7ce1e7a commit d87739f
Showing 1 changed file with 28 additions and 66 deletions.
94 changes: 28 additions & 66 deletions src/android/CameraPreviewFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,50 +157,6 @@ public void startCamera() {
return;
}

CameraSelector cameraSelector = new CameraSelector.Builder()
.requireLensFacing(direction)
.build();

Size targetResolution = null;
if (targetSize > 0) {
targetResolution = CameraPreviewFragment.calculateResolution(getContext(), targetSize);
}

Recorder recorder = new Recorder.Builder()
.setQualitySelector(QualitySelector.from(Quality.LOWEST))
.build();
videoCapture = VideoCapture.withOutput(recorder);


preview = new Preview.Builder().build();
imageCapture = new ImageCapture.Builder()
.setTargetResolution(targetResolution)
.build();
this.getActivity().runOnUiThread(() -> {
try {
cameraProvider.unbindAll();
camera = cameraProvider.bindToLifecycle(
this,
cameraSelector,
preview,
imageCapture,
videoCapture
);
} catch (IllegalArgumentException e) {
// Error with result in capturing image with default resolution
e.printStackTrace();
imageCapture = new ImageCapture.Builder()
.build();
camera = cameraProvider.bindToLifecycle(
this,
cameraSelector,
preview,
imageCapture,
videoCapture
);
}

});
setUpCamera(captureDevice,cameraProvider);
preview.setSurfaceProvider(viewFinder.getSurfaceProvider());

Expand Down Expand Up @@ -515,31 +471,37 @@ public void setUpCamera(String captureDevice, ProcessCameraProvider cameraProvid
targetResolution = CameraPreviewFragment.calculateResolution(getContext(), targetSize);
}

Recorder recorder = new Recorder.Builder()
.setQualitySelector(QualitySelector.from(Quality.LOWEST))
.build();
videoCapture = VideoCapture.withOutput(recorder);


preview = new Preview.Builder().build();
imageCapture = new ImageCapture.Builder()
.setTargetResolution(targetResolution)
.build();

cameraProvider.unbindAll();
try {
camera = cameraProvider.bindToLifecycle(
getActivity(),
cameraSelector,
preview,
imageCapture
);
} catch (IllegalArgumentException e) {
// Error with result in capturing image with default resolution
e.printStackTrace();
imageCapture = new ImageCapture.Builder()
.build();
camera = cameraProvider.bindToLifecycle(
getActivity(),
cameraSelector,
preview,
imageCapture
);
}

cameraProvider.unbindAll();
try {
camera = cameraProvider.bindToLifecycle(
getActivity(),
cameraSelector,
preview,
imageCapture,
videoCapture
);
} catch (IllegalArgumentException e) {
// Error with result in capturing image with default resolution
e.printStackTrace();
imageCapture = new ImageCapture.Builder()
.build();
camera = cameraProvider.bindToLifecycle(
getActivity(),
cameraSelector,
preview,
imageCapture,
videoCapture
);
}
}
}

0 comments on commit d87739f

Please sign in to comment.