rememberCamera

fun rememberCamera(isActive: Boolean, device: CameraDeviceOrPosition, outputs: List<CameraOutput> = emptyList(), constraints: List<Constraint> = emptyList(), mirrorMode: MirrorMode = MirrorMode.AUTO, orientationSource: OrientationSource? = OrientationSource.DEVICE, zoom: Double? = null, exposure: Double? = null, torchMode: TorchMode? = null, controllerConfiguration: CameraControllerConfiguration = CameraControllerConfiguration(), sessionConfiguration: CameraSessionConfiguration = CameraSessionConfiguration(), onSessionConfigSelected: (CameraSessionConfig) -> Unit? = null, onConfigured: () -> Unit? = null, onStarted: () -> Unit? = null, onStopped: () -> Unit? = null, onError: (Throwable) -> Unit = { println("VisionCamera error: $it") }, onInterruptionStarted: (InterruptionReason) -> Unit? = null, onInterruptionEnded: () -> Unit? = null, onSubjectAreaChanged: () -> Unit? = null, onUIRotationChanged: (rotation: Int) -> Unit? = null): CameraController?

Use the Camera (the equivalent of VisionCamera's useCamera).

This creates a CameraSession, configures it with the device and outputs whenever they change, starts it while isActive is true, applies the orientationSource's orientation to all outputs, forwards its events to the given callbacks, applies zoom, exposure and torchMode declaratively, and returns the CameraController.

val previewOutput = rememberPreviewOutput()
val controller = rememberCamera(
isActive = true,
device = TargetCameraPosition.BACK,
outputs = listOf(previewOutput),
)
NativePreviewView(previewOutput, Modifier.fillMaxSize())

Return

The CameraController, or null while the session is not configured yet.

Parameters

isActive

Starts the session when true, and stops it when false.

device

The me.nathanfallet.visioncamera.CameraDevice to open, or a me.nathanfallet.visioncamera.TargetCameraPosition to use the default device at that position.

outputs

The CameraOutputs the device streams into.

constraints

Constraints the session tries to match, ranked by priority. Like VisionCamera's useCamera, a ResolutionBiasConstraint for each of the outputs is added after them, with a lower priority.

mirrorMode

Whether the outputs are mirrored. MirrorMode.AUTO mirrors selfie cameras.

orientationSource

The OrientationSource whose orientation is automatically applied to all outputs (see CameraOutput.outputOrientation), or null to set it yourself (VisionCamera's 'custom').

zoom

The zoom value, applied declaratively.

exposure

The exposure bias, applied declaratively.

torchMode

The torch mode, applied declaratively.

controllerConfiguration

Low-light boost, smooth auto-focus and distortion correction.

sessionConfiguration

Session-wide configuration (iOS audio and haptics behavior).

onSessionConfigSelected

Called once the constraints have been resolved.

onConfigured

Called whenever the session has been configured.

onStarted

Called when the session started.

onStopped

Called when the session stopped.

onError

Called when the session encountered an error.

onInterruptionStarted

Called when the session was interrupted.

onInterruptionEnded

Called when an interruption ended.

onSubjectAreaChanged

Called when the subject area substantially changes, e.g. when the user pans away from a scene previously in focus: a good point to reset locked focus. iOS only, like V5, see CameraController.addSubjectAreaChangedListener.

onUIRotationChanged

Called when the output orientation (driven by orientationSource) or the interface orientation changes, with the rotation in degrees (-90, 0, 90 or 180) that UI elements such as Camera controls need to appear upright.