Version - 0.0.1
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");
}
}
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
class CameraConfiguration {
final TruvideoSdkCameraLensFacing lensFacing;
final TruvideoSdkCameraFlashMode flashMode;
final TruvideoSdkCameraOrientation orientation;
final String outputPath;
final TruvideoSdkCameraModeType mode;
}
Lens Facing
TruvideoSdkCameraLensFacing
enum represents the two possible directions of a camera lens: back or front.
public enum TruvideoSdkCameraLensFacing {
case back
case front
}
Flash Mode
TruvideoSdkCameraFlashMode
enum defines two flash modes: off and on, offering developers control over flash functionality during media capture.
public enum TruvideoSdkCameraFlashMode {
case off
case on
}
Orientation
TruvideoSdkCameraModeType
enum offers four orientation choices: portrait, landscapeLeft, landscapeRight, and portraitReverse, enabling developers to define camera orientation preferences for media capture.
public enum TruvideoSdkCameraOrientation {
case portrait
case landscapeLeft
case landscapeRight
case portraitReverse
}
Camera Mode
CameraMode
offers you to determines whether the camera captures video, images, or both.
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.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.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).CameraMode.singleImage()
configures the camera to capture a single image, disabling video capture. The camera auto-closes after capture.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).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.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).
CameraConfiguration(
mode: CameraMode.videoAndImage(),
// mode: CameraMode.video(),
// mode: CameraMode.image(),
// mode: CameraMode.singleImage(),
// mode: CameraMode.singleVideo(),
// mode: CameraMode.singleMedia(),
// mode: CameraMode.singleVideoOrImage(),
);
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.
class TruvideoSdkCameraMedia {
final String createdAt;
final String filePath;
final TruvideoSdkCameraMediaType type;
final TruvideoSdkCameraLensFacing cameraLensFacing;
final TruvideoSdkCameraOrientation rotation;
final TruvideoSdkCameraResolution resolution;
final int duration;
}
public enum TruvideoSdkCameraMediaType {
case IMAGE
case VIDEO
}
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
TruvideoCameraSdk.events.listen((event) {
setState(() {
print("Event Type: ${event.type}");
print("Event Data: ${event.data?.toJson()}");
});
});
Event Class: TruvideoSdkCameraEvent
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.
class TruvideoSdkCameraEvent {
final String type;
final TruvideoSdkCameraEventData? data;
}
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?