# CameraXSource

public class **CameraXSource** extends [Object](https://developer.android.com/reference/java/lang/Object.html)  
implements LifecycleOwner Manages the camera in conjunction with an underlying `https://developers.google.com/android/reference/com/google/mlkit/vision/interfaces/Detector` and
`https://developers.google.com/android/reference/com/google/mlkit/vision/camera/DetectionTaskCallback`.
This receives preview frames from the camera at a specified rate, sending those frames to the
detector as fast as it is able to process those frames.

This camera source is using CameraX APIs internally.

The following Android permission is required to use the camera:

- android.permissions.CAMERA

### Public Constructor Summary

|---|---|
|   | [CameraXSource](https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraXSource#CameraXSource(com.google.mlkit.vision.camera.CameraSourceConfig))([CameraSourceConfig](https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig) cameraSourceConfig) Create a `https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraXSource` with given `https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig`. |
|   | [CameraXSource](https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraXSource#CameraXSource(com.google.mlkit.vision.camera.CameraSourceConfig,%20androidx.camera.view.PreviewView))([CameraSourceConfig](https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig) cameraSourceConfig, PreviewView previewView) Create a `https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraXSource` with given `https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig` and a `https://developers.google.com/android/reference/androidx/camera/view/PreviewView` for the preview frames to be displayed to the user. |

### Public Method Summary

|---|---|
| void | [close](https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraXSource#close())() Closes the camera and releases the resources of the camera and underlying detector. |
| int | [getCameraFacing](https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraXSource#getCameraFacing())() Returns the selected camera; one of `https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig#CAMERA_FACING_BACK` or `https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig#CAMERA_FACING_FRONT`. |
| [Size](https://developer.android.com/reference/android/util/Size.html) | [getPreviewSize](https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraXSource#getPreviewSize())() Returns the preview size that is currently in use by the underlying camera. |
| void | [start](https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraXSource#start())() Opens the camera and starts sending preview frames to the underlying detector. |
| void | [stop](https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraXSource#stop())() Stops the camera and releases the resources of the camera. |

### Inherited Method Summary

From class java.lang.Object

|---|---|
| [Object](https://developer.android.com/reference/java/lang/Object.html) | clone() |
| boolean | equals([Object](https://developer.android.com/reference/java/lang/Object.html) arg0) |
| void | finalize() |
| final [Class](https://developer.android.com/reference/java/lang/Class.html)\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| [String](https://developer.android.com/reference/java/lang/String.html) | toString() |
| final void | wait(long arg0, int arg1) |
| final void | wait(long arg0) |
| final void | wait() |

From interface androidx.lifecycle.LifecycleOwner

|---|---|
| abstract Lifecycle | getLifecycle() |

## Public Constructors

#### public **CameraXSource** ([CameraSourceConfig](https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig) cameraSourceConfig)

Create a `https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraXSource`
with given `https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig`.

#### public **CameraXSource** ([CameraSourceConfig](https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig) cameraSourceConfig, PreviewView previewView)

Create a `https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraXSource`
with given `https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig`
and a `https://developers.google.com/android/reference/androidx/camera/view/PreviewView` for
the preview frames to be displayed to the user.

## Public Methods

#### public void **close** ()

Closes the camera and releases the resources of the camera and underlying
detector.

#### public int **getCameraFacing** ()

Returns the selected camera; one of `https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig#CAMERA_FACING_BACK` or `https://developers.google.com/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig#CAMERA_FACING_FRONT`.

#### public [Size](https://developer.android.com/reference/android/util/Size.html) **getPreviewSize** ()

Returns the preview size that is currently in use by the underlying camera. The
result could be null if the PreviewView has not been started.

#### public void **start** ()

Opens the camera and starts sending preview frames to the underlying detector.

#### public void **stop** ()

Stops the camera and releases the resources of the camera.