# ConcurrentCamera

Artifact: [androidx.camera:camera-core](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/core/ConcurrentCamera.java+class:androidx.camera.core.ConcurrentCamera) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

*** ** * ** ***


```
public class ConcurrentCamera
```

<br />

*** ** * ** ***

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 `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner`. It includes a list of `https://developer.android.com/reference/androidx/camera/core/Camera`s which are operating at the same time. Before binding to `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner`, check `https://developer.android.com/reference/android/content/pm/PackageManager.html#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 `https://developer.android.com/reference/androidx/camera/core/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 `https://developer.android.com/reference/androidx/camera/core/UseCase`s bound for each. The max resolution is 720p or 1440p, more details in the following link, see [concurrent camera streaming](https://developer.android.com/reference/android/hardware/camera2/CameraManager#getConcurrentCameraIds())

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/camera/core/ConcurrentCamera.SingleCameraConfig` Configuration for a single camera in concurrent camera mode, including `https://developer.android.com/reference/androidx/camera/core/CameraSelector`, `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` and `https://developer.android.com/reference/androidx/camera/core/UseCaseGroup`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/camera/core/ConcurrentCamera#ConcurrentCamera(java.util.List<androidx.camera.core.Camera>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/core/Camera> cameras)` Constructor of concurrent cameras. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/core/Camera>` | `https://developer.android.com/reference/androidx/camera/core/ConcurrentCamera#getCameras()()` Gets the list of cameras. |
| `void` | `https://developer.android.com/reference/androidx/camera/core/ConcurrentCamera#setCompositionSettings(java.util.List<androidx.camera.core.CompositionSettings>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/core/CompositionSettings> compositionSettings )` Sets the composition settings for concurrent camera. |

## Public constructors

### ConcurrentCamera

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
public ConcurrentCamera(@NonNull List<Camera> cameras)
```

Constructor of concurrent cameras.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/core/Camera> cameras` | list of `https://developer.android.com/reference/androidx/camera/core/Camera`. |

## Public methods

### getCameras

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
public @NonNull List<Camera> getCameras()
```

Gets the list of cameras.

### setCompositionSettings

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/core/CompositionSettings> compositionSettings` | A list of `https://developer.android.com/reference/androidx/camera/core/CompositionSettings` for the concurrent cameras. The size of the list must be equal to the number of the cameras that were bound using `bindToLifecycle`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the camera is not in concurrent camera composition mode. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the size of the composition settings list does not match the number of cameras bound. |