Skip to main content
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​

ParameterTypeDescriptionRequiredDefault Value
tokenStringValid DICIO authentication token to authorize the use of the SDK.YesNone
callbackVideoRecorderCallbackImplementation to receive the resulting video and SDK events.YesNone
applicationIDStringYour application ID. Used for validation and licenses.YesNone
urlBaseStringBase URL of the server to validate the token and obtain the license.YesNone
videoDurationIntVideo duration in seconds. Only values from 10 to 30 are supported.No10
styledScreenVideoStyledObject that allows customizing the texts, primary and background colors.NoVideoStyled()

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:​

  1. onSuccess:

    • Description: Successful completion event. Returns the absolute path to the .mp4 file temporarily stored in the device cache (the file is replaced with each attempt to save space).
    • Parameter: videoFilePath (Physical path of the video).
  2. onCameraInfo:

    • Description: Sends metrics and hardware updates. The delivered format is a structured JSON.
    • Common Codes:
CodeDescription
CAMERA_STARTEDThe camera preview has been initialized successfully.
CAMERA_STOPPEDThe preview was stopped or released hardware usage.
RECORDING_STARTEDVideo and audio capture started.
ALREADY_RECORDINGThe start button was pressed but a recording was already running.
STOP_RECORDINGVideo stop was requested early or when time ended.
NO_RECORDINGAn attempt was made to stop a recording but none was in progress.
  1. onFailure:
    • Description: Triggered upon a validation error, permissions error, or connection failures.
    • Common Codes (Typically sent as JSON {"Code": "...", "Message": "..."}):
CodeDescription
VIDEO_DURATION_NOT_VALIDThe videoDuration parameter was initialized outside the allowed range of 10 to 30 seconds.
ERROR_PERMISSIONMandatory camera permission (CAMERA) was rejected.
WARNING_PERMISSIONAudio permission (RECORD_AUDIO) was rejected. The video will be recorded muted.
CAMERA_BIND_ERRORAn error occurred initializing the native CameraX service.
RECORDING_ERRORProblem storing or finishing the video file.
ERROR_JSON_EXCEPTIONError processing and building internal SDK responses.
  1. 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
)