Skip to content

Mobile Camera Configuration

In this example, we will show you how to configure the camera.

EngineConfiguration

All the basic engine configuration settings are part of the EngineConfiguration which are required to initialize the camera.

engineConfiguration = EngineConfiguration(
license = "<your license here>",
userId = "<your unique user id>",
),
  • license – the license to activate the Engine with.
license = "<your license here>",
  • userID – an optional unique ID tied to your application’s user. This helps us accurately calculate monthly active users (MAU). Especially useful when one person uses the app on multiple devices with a sign-in feature, ensuring they’re counted once. Providing this aids in better data accuracy. The default value is null.
userId = "<your unique user id>",

CameraConfiguration

You can optionally pass a CameraConfiguration object to the CaptureVideo.Input constructor to customise the camera experience and behaviour.

cameraConfiguration = CameraConfiguration(
recordingColor = Color.Blue,
maxTotalDuration = 30.seconds,
allowExceedingMaxDuration = false,
),
  • recordingColor – the color of the record button.
recordingColor = Color.Blue,
  • maxTotalDuration – the total duration that the camera is allowed to record.
maxTotalDuration = 30.seconds,
  • allowExceedingMaxDuration – Set to true to allow exceeding the maxTotalDuration.
allowExceedingMaxDuration = false,

Mode

You can optionally configure the initial mode of the camera.

Available Modes

  • Standard: the regular camera. This is the default.
  • Reaction(video, cameraLayoutMode, positionsSwapped): records with the camera while playing back a video.
    • video Uri of the video to react to.
    • cameraLayoutMode The layout mode. Available options are Horizontal and Vertical.
    • positionsSwapped A boolean indicating if the video and camera feed should swap positions. By default, it is false and the video being reacted to is on the top/left (depending on cameraLayoutMode)
cameraMode = CameraMode.Standard(),

Full Code

Here’s the full code:

import android.os.Bundle
import android.util.Log
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.ui.graphics.Color
import ly.img.camera.core.CameraConfiguration
import ly.img.camera.core.CameraMode
import ly.img.camera.core.CaptureVideo
import ly.img.camera.core.EngineConfiguration
import kotlin.time.Duration.Companion.seconds
private const val TAG = "ConfiguredCameraActivity"
class ConfiguredCameraActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val cameraInput = CaptureVideo.Input(
engineConfiguration = EngineConfiguration(
license = "<your license here>",
userId = "<your unique user id>",
),
cameraConfiguration = CameraConfiguration(
recordingColor = Color.Blue,
maxTotalDuration = 30.seconds,
allowExceedingMaxDuration = false,
),
cameraMode = CameraMode.Standard(),
)
setContent {
val cameraLauncher = rememberLauncherForActivityResult(contract = CaptureVideo()) { result ->
result ?: run {
Log.d(TAG, "Camera dismissed")
return@rememberLauncherForActivityResult
}
Log.d(TAG, "Result: $result")
}
Button(
onClick = {
cameraLauncher.launch(cameraInput)
},
) {
Text(text = "Open Camera")
}
}
}
}