Version - 1.0.3-beta.4

Camera Initialization

To initialize the camera, import the TruvideoCameraSdk module into the controller first. Next, customize the camera settings by utilizing CameraConfiguration with appropriate parameters to tailor it to your specific requirements.

Once the configuration is complete, proceed to display the camera view for capturing photos and clips.

import 'package:truvideo_camera_sdk/camera_configuration.dart';
import 'package:truvideo_camera_sdk/truvideo_camera_sdk.dart';
import 'package:truvideo_camera_sdk/truvideo_sdk_camera_flash_mode.dart';
import 'package:truvideo_camera_sdk/truvideo_sdk_camera_lens_facing.dart';
import 'package:truvideo_camera_sdk/truvideo_sdk_camera_mode_type.dart';
import 'package:truvideo_camera_sdk/truvideo_sdk_camera_orientation.dart';

Future<void> openCamera(String outputPath) async {
    final config = CameraConfiguration(
      lensFacing: TruvideoSdkCameraLensFacing.front, 
      //lensFacing: TruvideoSdkCameraLensFacing.front,
      //lensFacing: TruvideoSdkCameraLensFacing.back,
      flashMode: TruvideoSdkCameraFlashMode.off,
      //flashMode: TruvideoSdkCameraFlashMode.off,
      //flashMode: TruvideoSdkCameraFlashMode.on
      orientation: TruvideoSdkCameraOrientation.portrait,
      //orientation: TruvideoSdkCameraOrientation.portrait
      //orientation: TruvideoSdkCameraOrientation.landscapeRight,
      //orientation: TruvideoSdkCameraOrientation.landscapeRight,
      //orientation: TruvideoSdkCameraOrientation.portraitReverse,
      outputPath: outputPath,
      mode: CameraMode.videoAndImage(),
      // mode: CameraMode.videoAndImage(),
      // mode: CameraMode.video(),
      // mode: CameraMode.image(),
      // mode: CameraMode.singleImage(),
      // mode: CameraMode.singleVideo(),
      // mode: CameraMode.singleMedia(),
      // mode: CameraMode.singleVideoOrImage(),
    );

    try {
      List<TruvideoSdkCameraMedia> result = await TruvideoCameraSdk.openCamera(configuration: config);
    } catch (e) {
      print("Camera opening failed: $e");
    }
 }
 

Note The Camera module can run into errors if used by itself because it depends on a shared component. The Video module also uses this same component, and to avoid conflicts, TruVideo manages it within the Video module. This means:

  • If you use only the Camera module → errors may occur.

  • If you use the Camera and Video modules together → everything works smoothly, since the shared component is managed centrally

Entities

Preset

CameraConfiguration 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

CameraMode offers you to determines whether the camera captures video, images, or both.

  1. CameraMode.videoAndImage() sets the camera to support both video and image capture. This mode enables recording videos and capturing images. Parameters: durationLimit (int?, max video duration in seconds), videoMaxCount (int?, max videos), imageMaxCount (int?, max images). All default to no limit.

  2. CameraMode.video() configures the camera to capture only videos, disabling image capture. This mode restricts the camera to recording videos. Parameters: videoMaxCount (int?, max videos), durationLimit (int?, max video duration in seconds). Both default to no limit.

  3. CameraMode.image() configures the camera to capture only images, disabling video capture. This mode restricts the camera to taking images. Parameters: imageMaxCount (int?, max images, defaults to no limit).

  4. CameraMode.singleImage() configures the camera to capture a single image, disabling video capture. The camera auto-closes after capture.

  5. CameraMode.singleVideo() configures the camera to capture a single video, disabling image capture. The camera auto-closes after capture. Parameters: durationLimit (int?, max video duration in seconds, defaults to no limit).

  6. CameraMode.singleMedia() configures the camera to capture a single media item (video or image). This mode allows one media item based on user choice. Parameters: durationLimit (int?, max video duration in seconds), mediaCount (int?, typically 1). Both default to no limit.

  7. CameraMode.singleVideoOrImage() configures the camera to capture either a single video or image. The camera auto-closes after capture. Parameters: durationLimit (int?, max video duration in seconds, defaults to no limit).

Result

The results of TruvideoSDK camera operations, present an array of TruvideoSdkCameraMedia. Each TruvideoSdkCameraMedia object holds essential video attributes like createdAt, filePath, type, cameraLensFacing, rotation, resolution, and duration. Meanwhile, type defines the TruvideoSdkCameraMedia as photo or video as TruvideoSdkCameraMediaType.clip defines video and TruvideoSdkCameraMediaType.photo defines photo. This comprehensive data structure empowers developers to manage captured media seamlessly, facilitating integration and post-processing within their applications.

AR Camera

This documentation will provide the complete guide to implement AR camera.

Prerequisites

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

Steps to Implement AR Camera Call

  1. Import camera sdk

  1. AR Camera Configuration

Create AR Camera Configuration (similar to camera) before calling the AR Camera.

  1. Calling the Camera

You can call AR Camera with TruvideoCameraSdk.openArCamera function, and function will return List<TruvideoSdkCameraMedia>

AR Mode States

Inside the AR Camera 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 ( Android Specific ) :

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

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

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

Final Result

AR Camera Limitations ( Android Specific ) :

During the development of AR experiences using AR Core, it's common to require control over the camera resolution — for high-quality recordings, image processing, or performance (low resolution videos with 720p). However, AR Core restricts direct control over the camera resolution during an AR session, which can lead to confusion or misaligned expectations among developers. AR Core internally does not allow the user to change the camera session if it's too low for AR Core (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 AR Core may internally override it to ensure tracking quality.

Scanner Camera

The SDK provides openScanner function to open the scanner.

The SDK will return result as Future<String?>, which contains the scanned code data (e.g., QR code or barcode).

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: String The type of event that occurred.

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

Event Type :

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?