Camera

Import the following dependency in your file, here you will use these function.

import{
    initCameraScreen,    
    LensFacing,    
    FlashMode,    
    Orientation,    
    CameraMode,    
    CameraConfiguration
} from 'TruVideoCameraSdk';

Camera Configuration

Camera initialization requires camera configuration, Which we have to pass as a argument in initCameraScreen function. CameraConfiguration defines the settings for the camera, like lens facing direction, flash mode, orientation, output path, camera mode etc. This configuration allows developers to customize the camera's behavior and output to meet specific application needs.

CameraResult response is returned by initCameraScreen

interface CameraResult {
  id: string,
  createdAt: number,
  filePath: string,
  type: CameraMediaType,
  lensFacing: LensFacing,
  orientation: Orientation,
  resolution: Resolution,
  duration: number,
}
const cameraConfiguration: CameraConfiguration = {

    lensFacing: LensFacing.Front,
    //lensFacing: LensFacing.Back,

    flashMode: FlashMode.Off,
    //flashMode: FlashMode.On

    orientation: Orientation.Portrait,
    //orientation: Orientation.LandscapeLeft,
    //orientation: Orientation.LandscapeRight,
    //orientation: Orientation.PortraitReverse,
    //orientation: Orientation.Portrait,

    outputPath: '',
    frontResolutions: [],
    frontResolution: 'nil',
    backResolutions: [],
    backResolution: 'nil',
    mode: CameraMode.image(),
    //mode: CameraMode.video()
    //mode: CameraMode.videoAndImage()
    
    imageFormat : ImageFormat.JPEG
    // imageFormat : ImageFormat.PNG
  };

Output path will be responsible for where will be the recorded media will be placed in the app’s package

Camera Initialization

TruVideoCameraSdk is SDK containing the methods required to work with the camera module these are:-

// cameraConfiguration will be the configuration from above 
initCameraScreen(cameraConfiguration)
      .then((res) => {
         //handle response
         const mediaItem : CameraResult[] = res;

      })
      .catch((err) => {
         //handle error
        console.log('err', err);
      });

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.

Lens Facing

The LensFacing enum specifies the camera's direction, with two possible values:

  • LensFacing.Front: Uses the front-facing camera.

  • LensFacing.Back: Uses the back-facing camera.

export enum LensFacing {
  Back = 'BACK',
  Front = 'FRONT',
}

Flash Mode

The FlashMode enum controls the flash behavior during media capture, with two options:

  • FlashMode.On: Enables the flash.

  • FlashMode.Off: Disables the flash.

export enum FlashMode {
  Off = 'off',
  On = 'on',
}

Image Format

The Image Format enum controls the image behavior during media capture, with two options:

  • ImageFormat.JPEG: Enables the flash.

  • ImageFormat.PNG: Disables the flash.

export enum ImageFormat {
  JPEG = 'jpeg',
  PNG = 'png'
}

Orientation

The Orientation enum defines the camera's orientation for media capture. It includes four modes, or can be set to null for automatic orientation:

  • Orientation.Portrait: Standard portrait orientation.

  • Orientation.LandscapeLeft: Landscape with the left side up.

  • Orientation.LandscapeRight: Landscape with the right side up.

  • Orientation.PortraitReverse: Portrait with the top inverted.

  • null: Automatically adjusts orientation based on device.

export enum Orientation {
  Portrait = 'PORTRAIT',
  LandscapeLeft = 'LANDSCAPE_LEFT',
  LandscapeRight = 'LANDSCAPE_RIGHT',
  PortraitReverse = 'PORTRAIT_REVERSE',
}

Camera Mode

The CameraMode enum determines the capture mode of the camera, with three options:

  • CameraMode.image(): Configures the camera to capture only images, disabling video recording.

  • CameraMode.video(): Configures the camera to capture only videos, disabling image capture.

  • CameraMode.videoAndImage(): Configures the camera to support both video and image capture.

  • CameraMode.singleImage(): configures capture of one picture. Returns a TruvideoSdkCameraMediaMode instance.

  • CameraMode.singleVideo(): configures capture of one video with an optional duration limit (null for no limit). Returns a TruvideoSdkCameraMediaMode instance.

  • CameraMode.singleVideoOrImage(): configures capture of either one video or one picture with an optional video duration limit (null for no limit). Returns a TruvideoSdkCameraMediaMode instance.

  • CameraMode.videoAndImage(): 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 TruvideoSdkCameraMediaMode.

  • CameraMode.singleMedia(): 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 TruvideoSdkCameraMediaMode instance.

export class CameraMode {
  static singleMedia(mediaCount: number): CameraMode;
  static singleMedia(mediaCount: number,durationLimit?: number): CameraMode;
  static videoAndImage(): CameraMode;
  static videoAndImage(videoMaxCount?: number,imageMaxCount?: number,durationLimit?: number): CameraMode;
  static singleVideo(): CameraMode;
  static singleVideo(durationLimit?: number): CameraMode;
  static singleImage(): CameraMode;
  static singleVideoOrImage(): CameraMode;
  static singleVideoOrImage(durationLimit?: number): CameraMode;
  static video(): CameraMode;
  static video(videoMaxCount?: number): CameraMode;
  static video(videoMaxCount?: number,durationLimit?: number): CameraMode;
  static image(): CameraMode;
  static image(imageMaxCount?: number): CameraMode;
}

AR Camera

This documentation will provide the complete details for inplementing AR camera

Prerequisites

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

Steps to Implement AR Camera Call

  1. Initial Project Setup

import { initARCameraScreen, CameraMode, Orientation } from '@trunpm/truvideo-react-turbo-camera-sdk';
  1. AR Camera Configuration

Define the AR camera configuration in your React component. For example, to capture images in portrait mode:

var arConfig : ARCameraConfiguration = {
            outputPath: "",
            orientation: Orientation.Portrait,
            mode: CameraMode.image(),
        }
  1. Calling the Camera

Inside your React component, add a button to trigger the AR camera

import { Button, View } from 'react-native';

export default function App() {
  const openARCamera = () => {
    initARCameraScreen(arConfig)
      .then((response) => {
        console.log("AR response:", response);
      })
      .catch((err) => {
        console.log("AR error:", err);
      });
  };

  return (
    <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
      <Button title="Open AR Camera" onPress={openARCamera} />
    </View>
  );
}

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 ( Android Specific ) :

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.

const isAugInstalled = isAugmentedRealityInstalled();
const isAugmentSupported = isAugmentedRealitySupported();

Final Result

AR Camera Limitations ( Android Specific ) :

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.

Last updated

Was this helpful?