Learn how to get the recorded videos from the CameraReactionResult
and CameraRecordingResult
type of the openCamera
function.
Explore a full code sample on GitHub.
Success#
A Recording
has a duration
and contains an array of Video
s. The array contains either one Video
(for single camera recordings or a video that was reacted to) or two Video
s (for dual camera recordings.)
Each Video
has:
- A
path
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 theseRect
s 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 Recording
s, each representing a segment of the recorded video.
for (final recording in result.recordings) { print('Recording duration: ${recording.duration}'); for (final video in recording.videos) { print('Video path: ${video.path}'); print('Video rect: ${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 Recording
s, each representing a segment of the recorded video.
let camera = try Camera()
Task { try await engine.scene.zoom(to: page, paddingLeft: 40, paddingTop: 40, paddingRight: 40, paddingBottom: 40) for try await event in camera.captureVideo() {
Cancellation#
If the user has cancelled the camera session the openCamera
function will return null
.
if (result == null) { print('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.
print('Error occurred in the camera session: $error');
Full Code#
Here’s the full code for both files:
recordings_camera_solution.dart#
import 'package:flutter/material.dart';import 'package:imgly_camera/imgly_camera.dart';
class RecordingsExample extends StatelessWidget { @override Widget build(BuildContext context) { return ElevatedButton( onPressed: () async { final settings = CameraSettings( license: "YOUR-LICENSE-KEY", ); try { final result = await IMGLYCamera.openCamera(settings); if (result == null) { print('The editor has been cancelled.'); return; } for (final recording in result.recordings) { print('Recording duration: ${recording.duration}'); for (final video in recording.videos) { print('Video path: ${video.path}'); print('Video rect: ${video.rect}'); } } } catch (error) { print('Error occurred in the camera session: $error'); } }, child: Text('Open Camera'), ); }}