Android 12 Developer Preview is here! Try it out, and give us your feedback!

CameraController

abstract class CameraController
kotlin.Any
   ↳ androidx.camera.view.CameraController

The abstract base camera controller class.

This a high level controller that provides most of the CameraX core features in a single class. It handles camera initialization, creates and configures UseCases. It also listens to device motion sensor and set the target rotation for the use cases.

The controller is required to be used with a PreviewView. PreviewView provides the UI elements to display camera preview. The layout of the PreviewView is used to set the crop rect so the output from other use cases matches the preview display in a WYSIWYG way. The controller also listens to PreviewView's touch events to handle tap-to-focus and pinch-to-zoom features.

This class provides features of 4 UseCases: Preview, ImageCapture, ImageAnalysis and an experimental video capture. Preview is required and always enabled. ImageCapture and ImageAnalysis are enabled by default. The video capture feature is experimental. It's disabled by default because it might conflict with other use cases, especially on lower end devices. It might be necessary to disable ImageCapture and/or ImageAnalysis before the video capture feature can be enabled. Disabling/enabling UseCases freezes the preview for a short period of time. To avoid the glitch, the UseCases need to be enabled/disabled before the controller is set on PreviewView.

Summary

Constants
static Int

Bitmask option to enable ImageAnalysis.

static Int

Bitmask option to enable ImageCapture.

static Int

Bitmask option to enable video capture use case.

Public methods
open Unit

Removes a previously set analyzer.

open ListenableFuture<Void!>
enableTorch(torchEnabled: Boolean)

Enable the torch or disable the torch.

open CameraInfo?

Gets the CameraInfo of the currently attached camera.

open CameraSelector

Gets the CameraSelector.

open Int

Returns the mode with which images are acquired.

open Int

Gets the image queue depth of ImageAnalysis.

open Int

Gets the flash mode for ImageCapture.

open ListenableFuture<Void!>

Gets a ListenableFuture that completes when camera initialization completes.

open LiveData<Int!>

Returns a LiveData of current TorchState.

open LiveData<ZoomState!>

Returns a LiveData of ZoomState.

open Boolean
hasCamera(@NonNull cameraSelector: CameraSelector)

Checks if the given CameraSelector can be resolved to a camera.

open Boolean

Checks if ImageAnalysis is enabled.

open Boolean

Checks if ImageCapture is enabled.

open Boolean

Returns whether pinch-to-zoom is enabled.

open Boolean

Returns whether there is a in progress video recording.

open Boolean

Returns whether tap-to-focus is enabled.

open Boolean

Checks if video capture is enabled.

open Unit
setCameraSelector(@NonNull cameraSelector: CameraSelector)

Sets the CameraSelector.

open Unit
setEnabledUseCases(enabledUseCases: Int)

Enables or disables use cases.

open Unit
setImageAnalysisAnalyzer(@NonNull executor: Executor, @NonNull analyzer: ImageAnalysis.Analyzer)

Sets an analyzer to receive and analyze images.

open Unit

Sets the backpressure strategy to apply to the image producer to deal with scenarios where images may be produced faster than they can be analyzed.

open Unit

Sets the image queue depth of ImageAnalysis.

open Unit