Status Update
Comments
le...@google.com <le...@google.com> #2
Hi, thank you for reporting the issue.
An alternative way to get the Camera instance is via
However, you will need a lifecycleOwner, and if you don't want to bind any use cases, providing an empty use case array is allowed.
ex:
// Obtain the ProcessCameraProvider instance previously.
ListenableFuture<ProcessCameraProvider> cameraProviderFuture =
ProcessCameraProvider.getInstance(context);
cameraProviderFuture.addListener(() -> {
try {
mCameraProvider = cameraProviderFuture.get();
} catch (Exception e) {
// error handle
}
}, ContextCompat.getMainExecutor(context));
// Obtain Camera via bindToLifecycle
Camera camera = mCameraProvider.bindToLifecycle(mActivity, CameraSelector.DEFAULT_BACK_CAMERA, new UseCase[0]);
camera.getCameraInfo();
...
eu...@gmail.com <eu...@gmail.com> #3
If I do the code above in parallel with the binding CameraController
can I get any troubles? I will have two camera instances probably.
er...@google.com <er...@google.com>
le...@google.com <le...@google.com> #4
If you are using the same CameraSelector
for both CameraController.setCameraSelector()
and CameraProvider.bindToLifecycle()
, the Camera
references should point to the same Camera
instance. However, using CameraController
and CameraProvider.bindToLifecycle()
together is not a graceful means to obtain the Camera
instance, so we will consider adding API to CameraController
to get Camera
or CameraInfo
. Thanks again for your feedback.
xi...@google.com <xi...@google.com>
ap...@google.com <ap...@google.com> #5
Branch: androidx-main
commit 6eb38682d674db3f5f6088ebf20303745559d327
Author: Xi Zhang <xizh@google.com>
Date: Sat Jan 30 09:57:42 2021
API change: add camera info getter to CameraController
As per feature request from developers, we are adding a CameraInfo getter to CameraController. The functionality of this method overlaps with #getZoomState() and #getTorchState(), but those methods also provide additional wrapping to always return the latest state regardless of the camera being selected.
Relnote: add a CameraInfo getter to CameraController.
Bug: 178251727
Test: manual test and ./gradlew bOS
Change-Id: Ib8138c44ebc17164d3bf91d4dbc684a0fe7a2728
M camera/camera-view/api/current.txt
M camera/camera-view/api/public_plus_experimental_current.txt
M camera/camera-view/api/restricted_current.txt
M camera/camera-view/src/main/java/androidx/camera/view/CameraController.java
M camera/integration-tests/viewtestapp/src/androidTest/java/androidx/camera/integration/view/CameraControllerFragmentTest.kt
Description
CAMERA VIEW VERSION 1.0.0-alpha20
DESCRIPTION: There is no method to get torch availability in CameraController. Also, the camera is completely encapsulated so I can not check hasTroch() method.
ADDITIONAL INFORMATION: I managed to do it with the next, but it is not something I would like to do further:
or something a bit safer but maybe not accurate: