Video recording state#
The video recording state provides information on current state of recording function. It also indicates information such as starting date (or duration) of recording and saved media identifier.
Camera 1#
Sample code to monitor video recording state:
/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null
/** Monitors and prints video recording state. */
fun monitorRecordingState(drone: Drone) {
cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
// called on main thread when the camera peripheral changes
camera?.recordingState()?.run {
when (get()) {
CameraRecording.State.FunctionState.UNAVAILABLE ->
println("Video recording not available at present")
CameraRecording.State.FunctionState.STOPPED ->
println("Video recording stopped")
CameraRecording.State.FunctionState.STARTING ->
println("Video recording starting")
CameraRecording.State.FunctionState.STARTED ->
println("Video recording started, start time: ${recordStartTime()}")
CameraRecording.State.FunctionState.STOPPING ->
println("Video recording stopping")
CameraRecording.State.FunctionState.ERROR_INTERNAL,
CameraRecording.State.FunctionState.ERROR_INSUFFICIENT_STORAGE_SPACE,
CameraRecording.State.FunctionState.ERROR_INSUFFICIENT_STORAGE_SPEED ->
println("Video recording error: ${get()}")
CameraRecording.State.FunctionState.CONFIGURATION_CHANGE ->
print("Video recording will stop for internal reconfiguration")
}
latestMediaId()?.let { mediaId ->
print("Identifier of latest saved media: $mediaId")
}
}
}
}
Example of output during video recording:
Video recording starting
Video recording started, start time: Thu Feb 18 18:27:26 GMT+01:00 2021
Video recording stopping
Video recording stopped
Identifier of latest saved media: 10000558
Camera 2#
Video recording state is monitored with sub-component Camera.Recording
.
Sample code to monitor video recording state:
/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null
/** `MainCamera` peripheral. This is used to know when peripheral appears. */
private var mainCamera: Camera? = null
/** Monitors and prints video recording state. */
fun monitorRecordingState(drone: Drone) {
cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
// called on main thread when the camera peripheral changes
camera?.run {
// register sub-component listener, only when camera peripheral appears
if (mainCamera == null) {
// get notified every time recording sub-component changes
camera.component<Camera.Recording> { recording ->
recording?.apply {
when (val state = state) {
is Camera.Recording.State.Starting ->
println("Video recording starting")
is Camera.Recording.State.Started ->
println("Video recording started ${state.videoBitrate} ${state.mediaStorage} ${state.startTime}")
is Camera.Recording.State.Stopping -> {
println("Video recording stopping ${state.reason}")
state.savedMediaId?.let { mediaId ->
println("Identifier of saved media: $mediaId")
}
}
is Camera.Recording.State.Stopped -> {
println("Video recording stopped")
state.latestSavedMediaId?.let { mediaId ->
println("Identifier of latest saved media: $mediaId")
}
}
}
} ?: println("Video recording not available at present")
}
}
}
mainCamera = camera
}
}
Example of output during video recording:
Video recording stopped
Video recording starting
Video recording started 100000000 INTERNAL 1613669736367
Video recording stopping UserRequest
Identifier of saved media: 10000156
Video recording stopped
Identifier of latest saved media: 10000156