Concepts
The entry point for the recorder SDK is the RecorderProtocol
protocol.
This protocol provides functions to:
- start and stop the recording
- control the camera through
RecorderProtocol.camera
- configure the upload
- preview the recorded video
- build a responsive UI to show controls to the user.
The recorder will forward all relevant events to subscribers that were registered with the
addObserver
function. We recommend listening at least to the error event:
class CustomRecorderObserver : RecorderObserver {
func recorderResult(_ result: Recording) {
// handle result
}
func recorderError(_ error: Error) {
// handle error
}
}
let recorder: RecorderProtocol = ...
let observer = CustomRecorderObserver()
recorder.addObserver(observer) // or more easily, self
We provide different implementations that can be used within your app depending on your needs, but all of them share the same API surface described below.
Unlike Android, iOS recorder does not automatically request camera and/or microphone authorizations. It is up to you to do so using the
RecorderAuthorizations
class.
Recorder protocol
Recording
The recorder is able to record multiple clips together in a single file. This means that recording can be paused and resumed as many times as you want. To start recording:
recorder.start()
This will soon move the recorder.state
from RecorderState.idle
to RecorderState.recording
.
To pause recording:
recorder.pause()
This will bring back recorder.state
to RecorderState.idle
. At this point, the video is not finalized,
and you have different options:
- resume recording, with
recorder.start()
- confirm the video, with
recorder.stop()
- discard the video, with
recorder.reset()
The recorder can go through multiple start()
/ pause()
calls and the new video will
just be appended to the existing content. You can also change camera sensor and settings in between.
Recording and segments
As you record clips with start()
and pause()
, the recorder will expose information about
the recorded data with Recording
and Segment
objects:
// After the first start / pause cycle, you will find a non-null Recording
let recording: Recording? = recorder.recording
// List of clips, each one representing a start / pause cycle
let segments: [Segment] = recording.segments
// Recorded duration in milliseconds, keeps growing
let duration: TimeInterval = recorder.duration
Canceling the recording
To discard the recorded data (assuming it was not confirmed yet), simply call reset()
. This will
move the recorder to its original state, with no pending recording and zero segments:
recorder.reset()
Confirm the recording
To confirm the recorded data, simply call stop()
. This tells
the recorder that you are not planning to write anything else to this file.
recorder.stop()
After this call, you should soon receive a complete Recording
in the recorderResult()
listener callback.
The record will contain several properties, most importantly an URL
pointing to the resulting file.
Duration limits
The recorder has an option to stop recording automatically after a certain duration has been
reached. This duration can be set through recorder.maxDuration
as a TimeInterval
:
// Stop automatically after 15 seconds:
recorder.maxDuration = 15.0
Configuring video parameters
You can configure both audio and video capture and encoding parameters using the AudioOptions
and VideoOptions
class.
recorder.audioOptions = AudioOptions(
source: .microphone,
channels: 1
)
recorder.videoOptions: VideoOptions(
source: .camera,
bitRate: 5_000_000,
frameRate: 30,
size: .input,
orientation: .device,
encoding: .h265
)