VideoRecorderProtocol

public protocol VideoRecorderProtocol

Protocol to record a video with the rear camera.

Provides control over the recording process and camera preview. You can access the current state of the recording with status observable property.

The sequence of calls should be as follows:

  • initVideoRecorder(orientation) (usually onAppear and orientation change) call to init the rear camera and start receiving the preview into the previewLayer
  • startRecording() when the user presses the record button. This will start supplying the video frames to the recording session

When done:

  • stopRecording() when the user presses the stop button. Recording stops but previewLayer continues to show the camera view
  • stopVideoRecorder() (usually onDisappear) to stop the preview and shutdown the camera
  • current status of the recorder

    You can access the highlights found during the processing or after the processing is finished.

    Note

    this property updated only on the main thread

    Declaration

    Swift

    var status: VideoRecorderStatus { get set }
  • minimum zoom level for the camera

    Declaration

    Swift

    var userFacingMinZoom: CGFloat { get }
  • maximum zoom level for the camera

    Declaration

    Swift

    var userFacingMaxZoom: CGFloat { get }
  • current zoom level for the camera

    Declaration

    Swift

    var userFacingZoom: CGFloat { get set }
  • zoom level thresholds for the camera

    Declaration

    Swift

    var userFacingZoomThresholds: [CGFloat] { get }
  • max zoom level where the camera will start using digital zoom

    Declaration

    Swift

    var userFacingUpscaleZoom: CGFloat { get }
  • set new status object to track the video highlight processing

    Declaration

    Swift

    func setStatusObject(_ status: VideoRecorderStatus)
  • Initializes video recording session.

    When used in UI this method should be called onAppear and then call stopVideoRecorder onDisappear

    Note

    This method should not be called on a main thread, either use Task.init or DispatchQueue

    Declaration

    Swift

    @discardableResult
    func initVideoRecorder(orientation: AVCaptureVideoOrientation) -> Bool

    Parameters

    orientation

    orientation of the video according to the current phone orientation

    Return Value

    true on success

  • Stops everything related to video recording.

    When used in UI this method should be called onDisappear. Can be called on main thread.

    Declaration

    Swift

    func stopVideoRecorder()
  • Sets the camera orientation for the recording

    Should be called when the phone orientation changes. Has no effect if we are already recording. Can be called on main thread.

    Declaration

    Swift

    func changeVideoOrientation(_ new: AVCaptureVideoOrientation)

    Parameters

    new

    new orientation

  • Starts recording video, i.e user pressed record button in UI for example

    Can be called on main thread. It starts the recording initialization in async way. Check VideoRecorderStatus.isRecording to get if we actually recording

    Declaration

    Swift

    @discardableResult
    func startRecording() -> Bool

    Return Value

    true on success

  • Stops the recording if it is running now

    Can be called on main thread. It stops the recording in async way. Check VideoRecorderStatus.isRecording to get if we actually stopped.

    Declaration

    Swift

    @discardableResult
    func stopRecording() -> Bool

    Return Value

    true if the recording was running and is stopped now

  • Video preview layer to be used in UI to preview what we capture

    Note

    This prop is not null only after the initVideoRecorder() call

    Declaration

    Swift

    var previewLayer: AVCaptureVideoPreviewLayer? { get }
  • Sets the current zoom level of the video.

    Declaration

    Swift

    func setZoom(_ val: CGFloat)

    Parameters

    val

    new zoom level