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 isnull
.
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 totrue
to allow exceeding themaxTotalDuration
.
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 areHorizontal
andVertical
.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 oncameraLayoutMode
)
cameraMode = CameraMode.Standard(),
Full Code#
Here’s the full code:
import android.os.Bundleimport android.util.Logimport androidx.activity.compose.rememberLauncherForActivityResultimport androidx.activity.compose.setContentimport androidx.appcompat.app.AppCompatActivityimport androidx.compose.material3.Buttonimport androidx.compose.material3.Textimport androidx.compose.ui.graphics.Colorimport ly.img.camera.core.CameraConfigurationimport ly.img.camera.core.CameraModeimport ly.img.camera.core.CaptureVideoimport ly.img.camera.core.EngineConfigurationimport 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") } } }}