CameraSelector


class CameraSelector


A set of requirements and priorities used to select a camera or return a filtered set of cameras.

Summary

Nested types

Builder for a CameraSelector.

Constants

const CameraSelector

A static CameraSelector that selects the default back facing camera.

const CameraSelector

A static CameraSelector that selects the default front facing camera.

const Int

A camera on the device facing the opposite direction as the device's screen.

const Int

An external camera that has no fixed facing relative to the device's screen.

const Int

A camera on the device facing the same direction as the device's screen.

const Int

A camera on the devices that its lens facing is resolved.

Public functions

(Mutable)List<CameraInfo!>
filter(cameraInfos: (Mutable)List<CameraInfo!>)

Filters the input CameraInfos using the CameraFilters assigned to the selector.

String?

Returns the physical camera id.

Constants

DEFAULT_BACK_CAMERA

Added in 1.0.0
const val DEFAULT_BACK_CAMERACameraSelector

A static CameraSelector that selects the default back facing camera.

DEFAULT_FRONT_CAMERA

Added in 1.0.0
const val DEFAULT_FRONT_CAMERACameraSelector

A static CameraSelector that selects the default front facing camera.

LENS_FACING_BACK

Added in 1.0.0
const val LENS_FACING_BACK = 1: Int

A camera on the device facing the opposite direction as the device's screen.

LENS_FACING_EXTERNAL

Added in 1.3.0
@ExperimentalLensFacing
const val LENS_FACING_EXTERNAL = 2: Int

An external camera that has no fixed facing relative to the device's screen.

The behavior of an external camera highly depends on the manufacturer. Currently it's treated similar to a front facing camera with little verification. So it's considered experimental and should be used with caution.

LENS_FACING_FRONT

Added in 1.0.0
const val LENS_FACING_FRONT = 0: Int

A camera on the device facing the same direction as the device's screen.

LENS_FACING_UNKNOWN

Added in 1.3.0
const val LENS_FACING_UNKNOWN = -1: Int

A camera on the devices that its lens facing is resolved.

Public functions

filter

Added in 1.1.0
fun filter(cameraInfos: (Mutable)List<CameraInfo!>): (Mutable)List<CameraInfo!>

Filters the input CameraInfos using the CameraFilters assigned to the selector.

If the CameraFilters assigned to this selector produce a camera info that is not part of the input list, the output list will be empty.

An example use case for using this function is when you want to get all CameraInfos for all available back facing cameras.

eg.

          
CameraInfo defaultBackCameraInfo = null;
CameraSelector selector = new CameraSelector.Builder()
     .requireLensFacing(LENS_FACING_BACK).build();
List<CameraInfo> cameraInfos = selector.filter(cameraProvider.getAvailableCameraInfos());
Parameters
cameraInfos: (Mutable)List<CameraInfo!>

The camera infos list being filtered.

Returns
(Mutable)List<CameraInfo!>

The remaining list of camera infos.

Throws
java.lang.UnsupportedOperationException

If the CameraFilters assigned to the selector try to modify the input camera infos list.

java.lang.IllegalArgumentException

If the device cannot return the necessary information for filtering, it will throw this exception.

getPhysicalCameraId

Added in 1.4.0
fun getPhysicalCameraId(): String?

Returns the physical camera id.

If physical camera id is not set via setPhysicalCameraId, it will return null.

Returns
String?

physical camera id.