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 = null, // pass null or empty for evaluation mode with watermark userId = "<your unique user id>",),license– the license to activate the Engine with.
license = null, // pass null or empty for evaluation mode with watermarkuserID– 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 CaptureMedia.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 totrueto allow exceeding themaxTotalDuration.
allowExceedingMaxDuration = false,Capture Type and Count#
Two configuration axes control what the camera captures:
captureType–CaptureType.Video(default),CaptureType.Photo, orCaptureType.Mixed. InMixedmode the camera shows a photo↔video toggle so the user can switch modes during the session.captureCount–CaptureCount.Multi(default) lets the user stack multiple captures into one session;CaptureCount.Singlereturns after a single capture.photoClipDuration– the duration stamped on each captured photo when the editor later treats it as a clip. Defaults to5.seconds.showsPhotoPreview– whenfalse, photo captures are committed immediately without the confirm/discard preview screen. Useful for rapid-fire multi-take photo sessions. Defaults totrue.
val photoConfig = CameraConfiguration( captureType = CaptureType.Photo, captureCount = CaptureCount.Single,)Photo (captureType = CaptureType.Photo), Video (default), and Mixed sessions all deliver a CameraResult.Captures(List<Capture>), where each Capture is either Capture.Photo(uri, clipDuration) or Capture.Video(recording). Use the List<Capture>.videos extension to extract just the recordings when you only care about video clips.
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.videoUri of the video to react to.cameraLayoutModeThe layout mode. Available options areHorizontalandVertical.positionsSwappedA 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.CaptureMediaimport 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 = CaptureMedia.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 = CaptureMedia()) { result -> result ?: run { Log.d(TAG, "Camera dismissed") return@rememberLauncherForActivityResult } Log.d(TAG, "Result: $result") }
Button( onClick = { cameraLauncher.launch(cameraInput) }, ) { Text(text = "Open Camera") } } }}Localization#
The CE.SDK camera currently supports English and German languages on Android, however it provides convenient API to replace the values of existing localization keys or add support for more languages.
All the camera keys are located here and they all follow strict naming convention to make locating keys simple and self-explanatory.
For instance, the timer off button can be found via ly_img_camera_timer_option_off key, or the title in the alert dialog of deleting last recording can be found via ly_img_camera_dialog_delete_last_recording_title key.
Replacing existing keys#
In order to replace any of the existing camera keys, find the key of the desired text, copy the key to res/values/strings.xml file of your app module and replace with the desired value.
Supporting new languages#
In order to add support for a language that is not supported by the CE.SDK camera, copy the content of the English localization file to res/values-{desired-language-code}/strings.xml file and replace the values with desired translations.