Recording the Live View
A live stream can be recorded to the device’s gallery while it is playing. Recordings are written straight into the Android gallery through MediaStore, so the saved clips appear in the user’s Movies folder and in their photo gallery app.
Pre-requisite: The camera should already be streaming live view before starting a recording.
Start a recording
To start recording the live view, The following method can be used:
shouldInterpolate(required): Whether to interpolate frames to smooth the output. Passnullto use the default.minMp(required): The minimum megapixels of the recorded video. Passnullto use the default.minWidth(required): The minimum width of the recorded video. Passnullto use the default.minHeight(required): The minimum height of the recorded video. Passnullto use the default.fileName(optional): The base name of the saved clip. Defaults to the device name.
client.startRecording(
shouldInterpolate = null, // Use the default interpolation behaviour
minMp = null, // Use the default megapixels
minWidth = null, // Use the default width
minHeight = null, // Use the default height
fileName = "Front Door" // The base name of the saved clip
)
On a dual-lens camera one clip is recorded per sensor, and each file name is suffixed with the sensor number.
Stop a recording
To stop recording and save the clips, The following method can be used:
onSaved(optional): Receives the number of clips that were saved.
client.stopRecording { savedCount ->
// The number of clips written to the gallery
}
The callback reports how many clips were saved, not where they are. Because the SDK writes into the gallery as it records, there are no files to move or upload afterwards, and no file handles are returned.
Observe the recording state
To know whether a recording is in progress, the following property can be used:
viewModelScope.launch {
client.isRecording.collectLatest { isRecording ->
if (isRecording) {
// A recording is in progress
} else {
// No recording is in progress
}
}
}
Managing gallery entries yourself
Most apps never need this. If you drive WebRtcRecorder directly instead of going through LiveStreamClient, you are responsible for creating and publishing the gallery entries yourself.
createGalleryVideoTargetreserves a pending entry in the gallery and opens a descriptor to it. It returnsnullif the entry could not be created.publishGalleryVideoTargetcloses the descriptor and makes the entry visible to the user.discardGalleryVideoTargetcloses the descriptor and deletes the entry, for a recording that was abandoned.
val target = context.createGalleryVideoTarget("Front Door.mp4")
if (target != null) {
val output = WebRtcRecorder.SensorOutput(
crop = crop, // The region of the frame to record
outputDescriptor = target.descriptor // Write into the gallery entry
)
// Record using the output, then publish the entry once recording completes
context.publishGalleryVideoTarget(target)
}
A SensorOutput needs either an outputFile or an outputDescriptor, and it fails to construct if both are missing.