CameraWrapper

A high level implementation over CameraX that provides a streamlined API to interact with a hardware camera for preview, image analysis, image capture, and video recording.

NOTE: This class must be used from within the main thread.

Constructors

Link copied to clipboard
constructor(context: Context, lifecycleOwner: LifecycleOwner, cameraSettings: MiSnapSettings.Camera)

Functions

Link copied to clipboard
open override fun cancelAutoFocus()

Cancels an ongoing autofocus request. Calls to this method are ignored if the camera is not initialized.

Link copied to clipboard
open override fun getCameraInfo(): MiSnapCameraInfo?

Gets the support information of the hardware camera, or null if is not available.

Link copied to clipboard
open override fun getCurrentOpenedCameraId(): String?

Returns the id of the opened camera, or null if not available.

Link copied to clipboard
open override fun isInitialized(): Boolean

Determines if the camera has been selected and initialized.

Link copied to clipboard
open override fun openCameraInstance(cameraSelectorFilter: CameraSelectorFilter)

Selects and opens the best hardware camera candidate according to the supplied criteria, waiting for it to be available or claiming the resource if necessary.

Link copied to clipboard
open override fun release()

Releases all resources and resets all to its original state. This releases the hardware camera and stops the preview and its stream of frames.

Link copied to clipboard
open override fun requestAutoFocus(meteringPoint: MeteringPoint)

Requests the camera to perform an autofocus in the region of interest. The autofocus won't work if the camera does not support autofocus modes.

Link copied to clipboard
open override fun setTorchEnabled(enable: Boolean, torchChangedResultListener: (isSuccessful: Boolean) -> Unit?)

Requests the camera to change the torch state. If the camera does not have a torch unit then the torch change will fail.

Link copied to clipboard
open override fun startPreview(surface: Surface, requireTakePictureCapability: Boolean)

Initializes the start of the camera preview on screen and preview frames to consume.

open override fun startPreview(surfaceHolder: SurfaceHolder, requireTakePictureCapability: Boolean)

Initializes the start of the camera preview on screen and preview frames to consume, if the holders' underlying surface is null or invalid it will wait for it to be ready first.

open override fun startPreview(surfaceProvider: Preview.SurfaceProvider, requireTakePictureCapability: Boolean)

Initializes the start of the camera preview on screen and preview frames to consume, the surfaceProvider must supply a valid surface when requested and it is responsible for managing the lifecycle of the surface.

Link copied to clipboard
open override fun startVideoRecording()

Requests the camera to start the recording of a video, if there is already an ongoing video recording it will be stopped and discarded before starting the new video recording request.

Link copied to clipboard
open override fun stopPreview()

Stops the camera preview, doing so stops the stream of preview frames and the ability to interact safely with the camera. Calling this method while the camera is not initialized has no effect.

Link copied to clipboard
open override fun stopVideoRecording()

Stops an ongoing video recording if any. The video recording contents are published to videoRecordings if the video was successful.

Link copied to clipboard
open override fun takePicture()

Requests the camera to take a picture.

Properties

Link copied to clipboard
open override var customFocusMode: Int?

Sets a custom supported focus mode to use by the camera. If the value is set while the camera isn’t initialized it will be applied to the camera settings once it is.

Link copied to clipboard
open override val focusingEvents: LiveData<Boolean>

LiveData object that emits a boolean that shows if the camera is currently going through a focusing process from calling requestAutoFocus.

Link copied to clipboard

LiveData object that emits events and errors during the camera initialization and interaction.

Link copied to clipboard
open override val pictureFrames: LiveData<Frame?>

LiveData object that emits the frames when the camera can process a request to take a picture.

Link copied to clipboard
open override val previewFrames: LiveData<Frame?>

LiveData object that emits the preview frames.

Link copied to clipboard
open override val torchEvents: LiveData<Boolean>

LiveData object to emit the status of the torch state, True for on and False for off.

Link copied to clipboard
open override val videoRecordings: LiveData<ByteArray?>

LiveData object that emits the video recordings as a ByteArray once they're ready.