ConcurrentCamera
public class ConcurrentCamera
Concurrent camera is a new feature introduced from Android 11, which supports simultaneous streaming of camera devices, for example, it allows a device to have both the front and back cameras operating at the same time.
A concurrent camera object is returned after binding concurrent cameras to LifecycleOwner. It includes a list of Cameras which are operating at the same time. Before binding to LifecycleOwner, check FEATURE_CAMERA_CONCURRENT to see whether this device is supporting concurrent camera or not.
Concurrent camera also supports composition mode, where multiple camera streams are composited into a single stream. This can be used for Picture-in-Picture or other custom layouts. Use CompositionSettings to configure the layout of each camera stream.
CameraX currently only supports dual concurrent camera, which allows two cameras operating at the same time, with at most two UseCases bound for each. The max resolution is 720p or 1440p, more details in the following link, see concurrent camera streaming
Summary
Nested types |
|---|
public final class ConcurrentCamera.SingleCameraConfigConfiguration for a single camera in concurrent camera mode, including |
Public constructors |
|---|
ConcurrentCamera(@NonNull List<Camera> cameras)Constructor of concurrent cameras. |
Public methods |
|
|---|---|
@NonNull List<Camera> |
Gets the list of cameras. |
void |
setCompositionSettings(Sets the composition settings for concurrent camera. |
Public constructors
Public methods
setCompositionSettings
public void setCompositionSettings(
@NonNull List<CompositionSettings> compositionSettings
)
Sets the composition settings for concurrent camera.
This method can be used to dynamically update the composition settings of the concurrent cameras, for example, to change the position or size of a Picture-in-Picture window.
The composition settings will be applied to the cameras in the order they were bound. The first composition setting is for the primary camera, and the second is for the secondary camera.
The size of the compositionSettings list must be equal to the number of the cameras that were bound using bindToLifecycle.
The following code snippet demonstrates how to update the composition settings for a dual camera setup:
List<SingleCameraConfig> singleCameraConfigs = Arrays.asList(config1, config2); ConcurrentCamera concurrentCamera = cameraProvider.bindToLifecycle(singleCameraConfigs); // Primary becomes PiP, Secondary becomes full screen CompositionSettings primary = new CompositionSettings.Builder() .setOffset(0.5f, 0.5f) .setScale(0.3f, 0.3f) .setZOrder(1) // Display on top .build(); CompositionSettings secondary = new CompositionSettings.Builder() .setZOrder(0) .build(); // The size of the list must match the number of cameras bound (in this case, 2) concurrentCamera.setCompositionSettings(Arrays.asList(primary, secondary));
| Parameters | |
|---|---|
@NonNull List<CompositionSettings> compositionSettings |
A list of |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if the camera is not in concurrent camera composition mode. |
java.lang.IllegalArgumentException |
if the size of the composition settings list does not match the number of cameras bound. |