DeepMedia logodeepmedia

Camera SDK

Version 0.8.5

Search

Choose platform

Other versions of this page

Devices

Once you allocate a camera manager, you can start to query and interact with the device sensors, represented by the io.deepmedia.camera.CameraDeviceCameraDevice class.

Selecting Devices

You can access a list of all devices using CameraManager.devices. If needed, you can select them by inspecting their properties:

kotlin logokotlin
val manager: CameraManager = ... val frontCamera: CameraDevice? = manager.devices.firstOrNull { it.direction == CameraDevice.Direction.Front }
swift
let manager: CameraManager = ... let frontCamera: CameraDevice? = manager.devices.first { $0.direction == .front }

Some of the device properties you may consider are:

  • id: String: a unique identifier for this device
  • direction: CameraDevice.Direction: either front, back or external
  • children: [CameraDevice]: the underlying devices for logical cameras made of multiple physical sensors under the hood
  • capabilities: CameraCapabilities: a precise description of what this device can do

As you go through the guide, you'll learn about more properties that can be used for selection.

Managing Devices

Open

For a device to be used in any way it must be opened first, and that's done via the openDevice function:

kotlin logokotlin
suspend fun openDevice( id: String? = null, direction: CameraDevice.Direction? = null ): CameraDevice = ...
swift
func openDevice( id: String? = nil, direction: CameraDevice.Direction? = nil ) async throws -> CameraDevice { ... }

Opening a camera means making it active and ready to be used for the use-cases you declared during initialization. For example:

  • If the preview feature was selected, the camera will stream into any preview surface that you define
  • If the picture feature was selected, the camera gets ready to receive the takePicture command
  • If the video feature was selected, the camera gets ready to interact with the recorder
  • If the barcode feature was selected, the camera will start looking for barcodes in the scene

In general, it makes the camera ready to do what you intended to do.

Close

Once you're done with a camera, you can either open another one, or close all of them.

kotlin logokotlin
suspend fun closeDevices(): Unit = ...
swift
func closeDevices() async throws { ... }
⚠️

Tip: use CameraManager.flipDevice() for the manager to check what camera is currently open, and open one that has the opposite direction.

Observing Devices

Current Device

Only one device can be opened at any given time. You can retrieve and observe changes with the CameraManager.currentDevice property:

kotlin logokotlin
val current: CameraDevice? = manager.currentDevice.value val flow: StateFlow<CameraDevice?> = manager.currentDevice
swift
let current: CameraDevice? = manager.currentDevice let publisher: AnyPublisher<CameraDevice?, Never> = manager.currentDevicePublisher

Device Status

At any given time, a single device has a status represented by the CameraDevice.Status enum:

kotlin logokotlin
val current: CameraDevice.Status = device.status.value val flow: StateFlow<CameraDevice.Status> = device.status
swift
let current: CameraDevice.Status = device.status let publisher: AnyPublisher<CameraDevice.Status, Never> = device.statusPublisher

Check the table below to understand the meaning of each status enum case:

StatusMeaning
CameraDevice.Status.Closed.closedDevice is in its closed, idle state.
CameraDevice.Status.Open.openDevice was opened by the manager and is currently active, connected and ready to receive commands.
CameraDevice.Status.Streaming.streamingLike the open state, but on top, the device is currently streaming image data in real-time (for preview, video recording, and/or barcode detection).
CameraDevice.Status.Unavailable.unavailableDevice has become unavailable, e.g. because camera permissions were not granted by the user, it was disconnected, it's in use by another app, or other hardware-related reasons.

Subscribe to the DeepMedia Newsletter

The latest news about DeepMedia products, open source projects and software development at our company.

By clicking “Subscribe”, you agree that DeepMedia may use your email address to send you newsletters, including commercial communications, and to process your personal data for this purpose. You agree that DeepMedia may process said data using third-party services for this purpose in accordance with the DeepMedia Privacy Policy. You can revoke this consent at any time using the unsubscribe link included in each email or by writing at contact@deepmedia.io.