79.1.1+

Camera Initialization

TruvideoSdkCamera is the single class containing the methods required to work with the camera module these are

  • ActivityResultLauncher<TruvideoSdkCameraConfiguration>: Launches the camera screen using the TruvideoSdkCameraContract and handles the returned media results.

    • Returns: ActivityResultLauncher<TruvideoSdkCameraConfiguration>: A launcher object that can be used to start the camera activity.

The result parameter is a List<TruvideoSdkCameraMedia>, containing media objects captured by the camera. The structure of TruvideoSdkCameraMedia should be documented separately as it depends on the Truvideo SDK.

circle-info

Hint

  • The // Handle result comment should be replaced with actual code to process the captured media.

  • Consider adding error handling for cases where the camera activity is canceled or fails.

  • If the TruvideoSdkCameraConfiguration object has significant properties, provide more details about its purpose.

  • For better readability, consider using descriptive variable names instead of result.

import com.truvideo.sdk.camera.TruvideoSdkCamera;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraConfiguration;
import com.truvideo.sdk.camera.ui.activities.camera.TruvideoSdkCameraContract;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraMedia;
import androidx.activity.result.ActivityResultLauncher;

public class YourActivity extends AppCompatActivity{
    ActivityResultLauncher<TruvideoSdkCameraConfiguration> cameraScreenLauncher;
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        cameraScreenLauncher = registerForActivityResult(
                    new TruvideoSdkCameraContract(),
                    result -> {
                        // Handle result
                    }
        );
        //...rest of your code
    }
}
  • launch(truvideoSdkCameraConfiguration): This function is responsible for starting the camera view it takes TruvideoSdkCameraConfiguration as input

    • TruvideoSdkCameraConfiguration: this is a data class that contains camera configuration data.

Augmented Reality (AR)

This document explains how to use the AR camera from a contract in an Android application using the Truvideo SDK. It provides instructions on how to launch both the standard camera and the AR camera from an activity using the TruvideoSdkArCameraContract.

Prerequisites

  • Ensure you have included the necessary Truvideo SDK dependencies in your project.

Steps to Implement AR Camera Call

  1. Initial Project Setup

    Ensure that your project is correctly configured with the following libraries:

    • Activity Result API to handle camera interaction.

    • Truvideo SDK libs, to enable camera functionalities.

  2. Declare Camera Launchers

    In your Activity where you want to launch the camera, define the launchers for both the regular camera and the AR camera.

  1. Camera Configuration

    Define the camera configuration using TruvideoSdkCameraConfiguration. In this example, we set a video and picture capture mode with specific constraints (max videos, photos, and duration limits).

  1. Calling the Camera

    Inside the UI, you can add buttons that launch both the regular camera and the AR camera. Here’s how you can open the AR camera when the user taps the corresponding button.

This button will trigger the AR camera using the previously defined configuration.

AR Mode states

Inside the ARCamera module, we have 3 AR Mode States: Object (arrow), Ruler and Record. By default we will have an AR Cursor and the AR Mode RULER.

  • OBJECT: Allows the user to add a 3D Object on the AR Cursor, in this case an arrow.

  • RULER: Allows the user to meter with our AR Ruler a determined 3D space.

  • RECORD: Hiddens the AR Cursor so we can focus on the media recording.

AR Camera Validations

Inside the ARCamera module, we validate whether the device supports or has ARCore installed, in those case scenarios, we have 2 values that can return that information:

  • isAugmentedRealitySupported: This property determines whether the device's hardware supports ARCore. It is essential to validate this before attempting any augmented reality operations, as trying to use ARCore on an unsupported device will result in runtime errors or unexpected behavior.

  • isAugmentedRealityInstalled: This property checks whether the ARCore services are installed on the device. Even if the device supports ARCore, it may not have the required services installed. By verifying this property, developers can avoid runtime issues by prompting users to install ARCore if necessary.

Final Result

AR Camera Limitations

During the development of AR experiences using ARCore, it's common to require control over the camera resolution — for high-quality recordings, image processing, or performance (low resolution videos with 720p). However, ARCore restricts direct control over the camera resolution during an AR session, which can lead to confusion or misaligned expectations among developers. ARCore internally does not allow the user to change the camera session if it's too low for ARCore (minimum currently on our tests was 1080p) or if the device itself does not allow it.

📚 Official References and Sources about limitations

AR Camera Recommendations

  • Do not assume Camera2-like behavior when working with ARCore’s camera stream.

  • Avoid restarting the AR session solely to apply a different resolution — this often leads to crashes or resource leaks.

  • Always validate the selected CameraConfig, but understand that ARCore may internally override it to ensure tracking quality.

Scanner Camera Initialization

TruvideoSdkCameraScanner is the single class containing the methods required to work with the scanner module.

  • ActivityResultLauncher<TruvideoSdkCameraScannerConfiguration>: Launches the scanner screen using the TruvideoSdkCameraScannerContract and handles the scanned code result.

  • Returns: ActivityResultLauncher<TruvideoSdkCameraScannerConfiguration> – A launcher object that can be used to start the scanner activity.

  • Result Parameter: A TruvideoSdkCameraScannerCode?, which contains the scanned code data (e.g., QR code or barcode).

  • Validation: You can implement custom validation logic by providing a TruvideoSdkCameraScannerValidation. The validator receives the scanned code and returns a TruvideoSdkCameraScannerValidationResult to either accept or reject the scanned value.

Entities

Preset

TruvideoSdkCameraConfiguration is a public class that encapsulates the configuration parameters for the TruvideoSDK camera. It includes settings such as the lens facing direction (front or back), flash mode, video orientation, output path for saved content, preferred video codec, and camera mode. This structure allows developers to customize camera behavior and output format to suit specific application requirements

Lens Facing

TruvideoSdkCameraLensFacing enum represents the two possible directions of a camera lens: back or front.

Flash Mode

TruvideoSdkCameraFlashMode enum defines two flash modes: off and on, offering developers control over flash functionality during media capture.

Orientation

TruvideoSdkCameraOrientation enum offers four orientation choices: portrait, landscapeLeft, landscapeRight, and portraitReverse, enabling developers to define camera orientation preferences for media capture.

Camera Mode

TruvideoSdkCameraMode enum includes three modes: video and picture, video, and picture, enabling developers to specify whether the camera should capture both video and pictures, only video, or only pictures, respectively.

  1. Image configures capture of multiple pictures with an optional limit on maxCount (null for no limit). Returns a TruvideoSdkCameraMode instance.

  2. SingleImage configures capture of one picture. Returns a TruvideoSdkCameraMode instance.

  3. singleVideo configures capture of one video with an optional duration limit (null for no limit). Returns a TruvideoSdkCameraMode instance.

  4. singleVideoOrPicture configures capture of either one video or one picture with an optional video duration limit (null for no limit). Returns a TruvideoSdkCameraMode instance.

  5. video configures capture of multiple videos with optional limits on video count and duration (null for no limit). Returns a TruvideoSdkCameraMode instance.

  6. videoAndPicture configures capture of videos and pictures with optional parameters: videoCount (maximum videos, null for no limit), pictureCount (maximum pictures, null for no limit), and videoDuration (maximum video duration in seconds, null for no limit). Returns the instance of TruvideoSdkCameraMode.

  7. videoAndPicture configures capture of videos and pictures with parameters: mediaCount (strict maximum combined videos and pictures) and videoDuration (maximum video duration in seconds, null for no limit). Returns a TruvideoSdkCameraMode instance.

Video Resolution

TruvideoSdkCameraResolution defines two camera resolution options: height and width, providing developers with choices for the resolution of video content within the TruvideoSDK.

Image Format

TruvideoSdkCameraImageFormat defines the format of capture Image by default it is JPEG, while there are 2 options JPEG and PNG

Output Data

The result of the camera returns the list of TruvideoSdkCameraMedia which contains the details about the video or photo capture which have these variables

  • createdAt (Long): Unix timestamp (in milliseconds) indicating the exact time the media was captured.

  • filePath (String): Full path to the captured media file (image or video) on the device's storage.

  • type (TruvideoSdkCameraMediaType): Enumerated value specifying the media type (VIDEO or PICTURE).

  • cameraLensFacing (TruvideoSdkCameraLensFacing): An enumerated value indicating the camera lens that captured the media (FRONT or BACK).

  • rotation (TruvideoSdkCameraOrientation): Enumerated value representing the media's orientation (e.g., PORTRAIT, LANDSCAPE).

  • resolution (TruvideoSdkCameraResolution): Enumerated value specifying the media's resolution containing the value of height, width, and aspect ratio.

  • duration (Long): Applicable only for video media; represents the video's duration in milliseconds.

Camera Events

The SDK communicates various camera-related events to consumers through a publisher that sends TruvideoSdkCameraEvent objects containing details about the event, including its type and creation date.

Event Observer

To observe camera events, consumers can register an observer using the provided Observer class. The observer listens for events and logs details about them.

Example Usage :

Event Class: TruvideoSdkCameraEvent

This class encapsulates the details of an event, including the event type, associated data, and the event's creation date.

Properties:

  • type: TruvideoSdkCameraEventType The type of event that occurred.

  • data: TruvideoSdkCameraEventData The data associated with the event. This data can vary depending on the event type.

  • createdAt: Date The date and time when the event was created.

Event Type Enum: TruvideoSdkCameraEventType

The TruvideoSdkCameraEventType enum defines the types of events that can be emitted by the Camera SDK.

Enum Values:

  • RecordingStarted Triggered when recording starts.

  • RecordingFinished Triggered when recording finishes.

  • RecordingPaused Triggered when recording is paused.

  • RecordingResumed Triggered when recording resumes.

  • PictureTaken Triggered when a picture is taken.

  • CameraFlipped Triggered when the camera is flipped between front and back.

  • ResolutionChanged Triggered when the camera resolution is changed.

  • FlashModeChanged Triggered when the flash mode is changed.

  • ZoomChanged Triggered when the zoom level is changed.

  • MediaDeleted Triggered when media is deleted.

  • MediaDiscard Triggered when media is discarded.

  • Continue Represents an event to continue clicked for saving photos and videos.

Last updated

Was this helpful?