The Recorder

Understanding how to use the Recorder to start, pause, resume and stop a Video Recording

The Recorder allows recording video and audio data to a file.

It is often created by a CameraVideoOutput. See "The Video Output" for more information.

const videoOutput = ...
const recorder = await videoOutput.createRecorder({
  // ...options
})

Starting a Recording

To start a Video Recording, use Recorder.startRecording(...), which takes callbacks for recording events:

const recorder = ...
await recorder.startRecording({
  (path) => console.log(`Recording finished!`),
  (error) => console.error(`Recording error!`, error),
  () => console.log(`Recording paused!`),
  () => console.log(`Recording resumed!`)
})

Inspecting Progress

As a recording progresses, you can inspect the Recorder's recordedDuration and recordedFileSize properties:

const recorder = ...
const interval = setInterval(() => {
  console.log(`Recorded ${recorder.recordedFileSize} bytes`)
}, 500)

The Recorder also exposes metadata about its state - like isRecording, isPaused and filePath.

Pausing/Resuming

To pause/resume Video Recordings, use Recorder.pauseRecording()/Recorder.resumeRecording(), which also fires the onRecordingPaused/onRecordingResumed callbacks previously passed to the Recorder.startRecording(...) function:

await recorder.pauseRecording()
await recorder.resumeRecording()

Stopping a Recording

To finish a Video Recording, use Recorder.stopRecording(), which requests the CameraVideoOutput to stop after all Frames have been successfully written.

await recorder.stopRecording()

This method resolves once the stop has been requested, but it may take a few Frames or sometimes even multiple seconds before the Video Recording will be finished - for example when using Video Stabilization, or when the device is throttled due to high thermal conditions.

Once the Video Recording has been finished, the onRecordingFinished callback passed to the Recorder.startRecording(...) function will be called.

Cancelling a Recording

To cancel a Video Recording instead of stopping it, use cancelRecording(), which deletes the file and cleans up state.

Interruptions

The Recorder gracefully handles interruptions such as incoming calls, minimizing the app, or pipeline stalls - in this case your CameraSession's onInterruptionStarted listener will get called. If the Recording has to be paused, the onRecordingPaused callback previously passed to the Recorder.startRecording(...) function will be called.

For incoming calls, the Recording doesn't have to be paused - only the audio track will be disabled, while video may continue to record.

Don't re-use a Recorder

A Recorder is single-use, meaning you need to create a new Recorder to record a new Video.