Skip to content

Access Recordings

Learn how to get the recorded videos from the CameraReactionResult and CameraRecordingResult type of the openCamera function.

Success

A Recording has a duration and contains an array of Videos. The array contains either one Video (for single camera recordings or a video that was reacted to) or two Videos (for dual camera recordings.)

Each Video has:

  • A uri to the video file that is stored in a temporary location. Make sure to copy the file to a permanent location if you want to access it later.
  • A rect that contains the position of each video as it was shown in the camera preview. For dual camera recordings, you can use these CGRects to arrange the videos as they were laid out in the camera.

Standard and Dual Camera

If the user has recorded videos, the openCamera will return a CameraRecordingResult which will contain an array of Recordings, each representing a segment of the recorded video.

result.recordings.forEach(recording => {
console.log(recording.duration);
recording.videos.forEach(video => {
console.log(video.uri);
console.log(video.rect);
});
});

Video Reaction

If the user has recorded a reaction, the openCamera will return a CameraReactionResult which will contain the video that was reacted to and an array of Recordings, each representing a segment of the recorded video.

console.log(result.video.duration);
result.video.videos.forEach(video => {
console.log(video.uri);
console.log(video.rect);
});
result.recordings.forEach(recording => {
console.log(recording.duration);
recording.videos.forEach(video => {
console.log(video.uri);
console.log(video.rect);
});
});

Cancellation

If the user has cancelled the camera session the openCamera function will return null.

if (result === null) {
console.log('The editor has been cancelled.');
return;
}

Failure

The openCamera function will throw if the user has not allowed accessing their camera and/or microphone or any other parsing/argument error occurred.

console.log(`Error occurred in the camera session: ${error}.`);

Full Code

Here’s the full code for both files:

recordings_camera_solution.ts

import IMGLYCamera, { CameraSettings } from '@imgly/camera-react-native';
export const recordings_camera_solution = async (): Promise<void> => {
const settings: CameraSettings = {
license: 'YOUR_LICENSE_KEY',
};
try {
const result = await IMGLYCamera.openCamera(settings);
if (result === null) {
console.log('The editor has been cancelled.');
return;
}
result.recordings.forEach(recording => {
console.log(recording.duration);
recording.videos.forEach(video => {
console.log(video.uri);
console.log(video.rect);
});
});
} catch (error) {
console.log(`Error occurred in the camera session: ${error}.`);
}
};

recordings_reaction_camera_solution.ts

import IMGLYCamera, { CameraSettings } from '@imgly/camera-react-native';
export const recordings_reaction_camera_solution = async (): Promise<void> => {
const settings: CameraSettings = {
license: 'YOUR_LICENSE_KEY',
};
try {
const result = await IMGLYCamera.openCamera(
settings,
require('MY_VIDEO_SOURCE'),
);
if (result === null) {
console.log('The editor has been cancelled.');
return;
}
console.log(result.video.duration);
result.video.videos.forEach(video => {
console.log(video.uri);
console.log(video.rect);
});
result.recordings.forEach(recording => {
console.log(recording.duration);
recording.videos.forEach(video => {
console.log(video.uri);
console.log(video.rect);
});
});
} catch (error) {
console.log(`Error occurred in the camera session: ${error}.`);
}
};