MÓDULO NATIVO
Video Recorder (Android)
This documentation provides a detailed guide for developers on how to integrate and implement the DICIO Video Recorder SDK into Android applications using Jetpack Compose. The SDK facilitates recording short videos (for proof of life, consent collection, etc.) applying time validations and hardware control transparently.
Regresar
ANDROIDJETPACK COMPOSEv2.2.0
Compatibilidad y Requisitos
Lenguaje
Kotlin / Java
OS Min
Android 7+
API / Target
API 24+
IDE
Jellyfish+
1. Project Setup
Configure your project dependencies by adding the library to your Gradle files and version catalog.
libs.versions.toml
[versions]
dicioVideo = "2.2.0"
[libraries]
dicio-videorecordersdk = { group = "io.bitbucket.juarezsdco", name = "videorecordersdk", version.ref = "dicioVideo" }
build.gradle
dependencies {
implementation(libs.dicio.videorecordersdk)
}
2. Basic Usage
The SDK is provided through the DicioVideoCamera Composable. Below is an example of how to implement the screen that invokes the SDK:
VideoSdkScreen.kt
package com.tuapp.yourapp
import ai.dicio.videorecordersdkjc.core.VideoRecorderCallback
import ai.dicio.videorecordersdkjc.ui.screens.camera.DicioVideoCamera
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@Composable
fun VideoSdkScreen(token: String?, urlBase: String) {
// Callback implementation
val sdkCallback = remember {
object : VideoRecorderCallback {
override fun onSuccess(videoFilePath: String) {
println("Video saved at path: $videoFilePath")
// Here you can close the screen or upload the file to the server
}
override fun onFailure(errorMessage: String) {
println("Video recording failed: $errorMessage")
}
override fun onCancel(cancelMessage: String) {
println("Process canceled: $cancelMessage")
}
override fun onCameraInfo(message: String) {
println("Camera info: $message")
}
}
}
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
if (token != null) {
DicioVideoCamera(
token = token,
callback = sdkCallback,
applicationID = "your.application.id", // Replace with your real ID
urlBase = urlBase,
videoDuration = 15 // Optional (10 to 30 seconds)
)
} else {
CircularProgressIndicator()
}
}
}
DicioVideoCamera Parameters
| Parameter | Type | Description | Required | Default Value |
|---|---|---|---|---|
token | String | Valid DICIO authentication token to authorize the use of the SDK. | Yes | None |
callback | VideoRecorderCallback | Implementation to receive the resulting video and SDK events. | Yes | None |
applicationID | String | Your application ID. Used for validation and licenses. | Yes | None |
urlBase | String | Base URL of the server to validate the token and obtain the license. | Yes | None |
videoDuration | Int | Video duration in seconds. Only values from 10 to 30 are supported. | No | 10 |
styledScreen | VideoStyled | Object that allows customizing the texts, primary and background colors. | No | VideoStyled() |
Result and Event Handling
You must implement the VideoRecorderCallback interface to react to all video recording flows.
VideoRecorderCallback
interface VideoRecorderCallback {
// Invoked when the recording finishes and the user confirms it.
fun onSuccess(videoFilePath: String)
// Invoked upon critical failures (e.g. denied permissions, camera errors).
fun onFailure(errorMessage: String)
// Invoked when the user goes back or explicitly cancels.
fun onCancel(cancelMessage: String)
// Emits camera and recording status updates.
fun onCameraInfo(message: String)
}
Detailed methods:
onSuccess:- Description: Successful completion event. Returns the absolute path to the
.mp4file temporarily stored in the device cache (the file is replaced with each attempt to save space). - Parameter:
videoFilePath(Physical path of the video).
- Description: Successful completion event. Returns the absolute path to the
onCameraInfo:- Description: Sends metrics and hardware updates. The delivered format is a structured JSON.
- Common Codes:
| Code | Description |
|---|---|
CAMERA_STARTED | The camera preview has been initialized successfully. |
CAMERA_STOPPED | The preview was stopped or released hardware usage. |
RECORDING_STARTED | Video and audio capture started. |
ALREADY_RECORDING | The start button was pressed but a recording was already running. |
STOP_RECORDING | Video stop was requested early or when time ended. |
NO_RECORDING | An attempt was made to stop a recording but none was in progress. |
onFailure:- Description: Triggered upon a validation error, permissions error, or connection failures.
- Common Codes (Typically sent as JSON
{"Code": "...", "Message": "..."}):
| Code | Description |
|---|---|
VIDEO_DURATION_NOT_VALID | The videoDuration parameter was initialized outside the allowed range of 10 to 30 seconds. |
ERROR_PERMISSION | Mandatory camera permission (CAMERA) was rejected. |
WARNING_PERMISSION | Audio permission (RECORD_AUDIO) was rejected. The video will be recorded muted. |
CAMERA_BIND_ERROR | An error occurred initializing the native CameraX service. |
RECORDING_ERROR | Problem storing or finishing the video file. |
ERROR_JSON_EXCEPTION | Error processing and building internal SDK responses. |
onCancel:- Description: The user interrupted the recording by closing the interface via the Back button.
- Cancellation Code: Typically sends
"USER_CANCEL".
3. Interface Customization (Optional)
If you need to adapt the interface to match your application's branding, you can make use of the VideoStyled object.
This class groups the text (strings) and color resources, allowing you to quickly dictate the background tones, buttons, and subtitles.
VideoStyled.kt
package ai.dicio.videorecordersdkjc.ui.models.settings
import ai.dicio.videorecordersdkjc.R
import androidx.compose.ui.graphics.Color
data class VideoStyled (
val title: Int = R.string.dicio_dv_title,
val subtitle: Int = R.string.dicio_dv_subtitle,
val titleSuccess: Int = R.string.dicio_dv_titile_success,
val titleColor: Color = Color(0xff000000), // Default Black
val subtitleColor: Color = Color(0xff313131), // Default Dark Gray
val backgroundColor: Color = Color(0xffffffff), // Default White Background
val primaryColor: Color = Color(0xff006407), // Institutional Green
val secondaryColor: Color = Color(0xff91ea97), // Secondary Green
)
Example of how to inject it into your view:
LivenessScreen.kt
val myStyle = VideoStyled(
// We customize to a Dark Mode view and blue buttons
backgroundColor = Color.Black,
titleColor = Color.White,
subtitleColor = Color.LightGray,
primaryColor = Color(0xFF007BFF) // Blue
)
DicioVideoCamera(
token = token,
callback = sdkCallback,
applicationID = "your.application.id",
urlBase = "https://your.base.url",
videoDuration = 10,
styledScreen = myStyle // <--- Assigned here
)