78.2.0+

Camera Initialization

To initialize the camera, import the TruvideoSdkCamera module into the controller first. Next, customize the camera settings by utilizing TruvideoSdkCameraConfiguration 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 TruvideoSdkCamera

 /**
     Initiates the camera functionality with specified parameters and presents the camera view.
     - Parameters:
        - viewController: The UIViewController or SwiftUIView where the camera view will be presented.
        - completion: A closure to handle the camera result upon completion.
            - cameraResult: The result of the camera operation.
     */
    func cameraInitiate(viewController: UIViewController, _ completion: @escaping (_ cameraResult: TruvideoSdkCameraResult) -> Void) {
        DispatchQueue.main.async {
            // Retrieving information about the device's camera functionality.
            let cameraInfo: TruvideoSdkCameraInformation = TruvideoSdkCamera.camera.getTruvideoSdkCameraInformation()
            
            // Configuring the camera with various parameters based on specific requirements.
            // - Parameter outputPath: Specifies the path for storing the captured data upon completion.
            // Additional parameters can be adjusted to customize camera behavior as needed.
            let configuration = TruvideoSdkCameraConfiguration(
                lensFacing: .back,
                flashMode: .off,
                outputPath: "",
                mode: .videoAndPicture()
                imageFormat: .jpeg
            )
            
            DispatchQueue.main.async {
                viewController.presentTruvideoSdkCameraView(
                    preset: configuration,
                    onComplete: { cameraResult in
                        // Handling completion of camera
                    }
                )
            }
        }
    }

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.

Augmented Reality (AR) [BETA]

Introducing the beta version of Augmented Reality (AR) functionality within the TruvideoSDK! This feature brings the power of augmented reality directly into your app, offering users an immersive and interactive experience like never before. To activate this feature, simply call the presentTruvideoSdkAugmentedRealityCameraView method from any UIViewController instance in your app.

Once invoked, users will be transported into the AR camera view, where they can capture stunning AR content, whether it's captivating images or engaging videos.

Upon completion of the AR session, a callback function is triggered, passing along a TruvideoSdkCameraResult. This allows seamless integration of the captured AR content back into your app, enabling further processing or integration with existing features.

Scanner Camera Initialization

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

Once the configuration is complete, proceed to display the camera view for scanning QR codes .

Entities

Preset

TruvideoSdkCameraConfiguration 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

Camera information

TruvideoSdkCameraInformation defines a structure holding information about available camera devices within the TruvideoSDK. It contains references to both front and back cameras, providing details such as device ID, lens facing direction, supported resolutions, flash availability, tap-to-focus capability, and sensor orientation. Developers can utilize this data to dynamically configure camera options and tailor the user experience accordingly.

Camera Resolution

TruvideoSdkCameraResolution is a class representing a specific resolution supported by a camera device. It includes attributes for width and height, allowing developers to ascertain available resolution options when configuring camera settings within their applications.

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

TruvideoSdkCameraMediaMode includes function modes enabling developers to specify whether the camera should capture both video and pictures, only video, or only pictures, respectively.

  1. videoAndPicture configures capture of videos and pictures with optional parameters: videoCount (maximum videos, nil for no limit), pictureCount (maximum pictures, nil for no limit), and videoDuration (maximum video duration in seconds, nil for no limit). Returns the instance of TruvideoSdkCameraMediaMode.

  2. singleVideo configures capture of one video with an optional duration limit (nil for no limit). Returns a TruvideoSdkCameraMediaMode instance.

  3. singlePicture configures capture of one picture. Returns a TruvideoSdkCameraMediaMode instance.

  4. singleVideoOrPicture configures capture of either one video or one picture with an optional video duration limit (nil for no limit). Returns a TruvideoSdkCameraMediaMode instance.

  5. video configures capture of multiple videos with optional limits on video count and duration (nil for no limit). Returns a TruvideoSdkCameraMediaMode instance.

  6. picture configures capture of multiple pictures with an optional limit on picture count (nil for no limit). Returns a TruvideoSdkCameraMediaMode instance.

  7. videoAndPicture configures capture of videos and pictures with parameters: mediaCount (strict maximum combined videos and pictures) and videoDuration (maximum video duration in seconds, nil for no limit). Returns a TruvideoSdkCameraMediaMode instance.

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.

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

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

  • createdAt: Date The date and time when the event was created.

Event Type Enum: TruvideoSdkCameraEventType

The TruvideoSdkCameraEventType enum defines 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?