Video recording start and stop#

Camera 1#

When can I start or stop recording ?#

Video recording can be started only when all of the following conditions are met:

  • camera is active: camera.isActive == true

  • camera mode is recording: camera.mode().value == Camera.Mode.RECORDING

  • recording state is stopped or one of the error states: camera.recordingState().get()

Video recording can be stopped when the following condition is true:

  • recording state is started: camera.recordingState().get() == CameraRecording.State.FunctionState.STARTED

The Camera API provides helper methods telling whether recording can be started are stopped:

  • camera.canStartRecording(): tells whether recording can be started

  • camera.canStopRecording(): tells whether recording can be stopped

Sample code to monitor whether video recording can be started or stopped :

/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null

/** Monitors and prints whether video recording can be started or stopped. */
fun monitorCanStartStopRecord(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        // called on main thread when the camera peripheral changes
        camera?.run {
            when {
                canStartRecording() ->
                    println("Video recording can be started")

                canStopRecording() ->
                    println("Video recording can be stopped")

                else ->
                    println("Video recording can't be started or stopped")
            }
        }
    }
}

How to start or stop recording ?#

Sample code to start and stop video recording:

/** Starts or stops video recording. */
fun toggleStartStopRecord(drone: Drone) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        when {
            // recording can be started
            canStartRecording() -> startRecording()

            // recording can be stopped
            canStopRecording() -> stopRecording()

            // recording can't be started or stopped
            else -> println("Video recording can't be started or stopped")
        }
    }
}

Camera 2#

When can I start or stop recording ?#

Video recording can be started only when all of the following conditions are met:

  • camera is active: camera.active == true

  • camera mode is recording: camera.config[Camera.Config.MODE].value == Camera.Mode.RECORDING

  • recording state is stopped: camera.component<Camera.Recording>()?.state is Camera.Recording.State.Stopped

Video recording can be stopped when the following condition is true:

  • recording state is started or starting:

    • camera.component<Camera.Recording>()?.state is Camera.Recording.State.Starting

    • OR camera.component<Camera.Recording>()?.state is Camera.Recording.State.Started

Sample code to monitor whether video recording can be started or stopped :

/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null

/** Monitors and prints whether video recording can be started or stopped. */
fun monitorCanStartStopRecord(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 ->
                    when(recording?.state) {
                        Camera.Recording.State.Starting,
                        is Camera.Recording.State.Started ->
                            println("Video recording can be stopped")

                        is Camera.Recording.State.Stopped ->
                            println("Video recording can be started")

                        else ->
                            println("Video recording can't be started or stopped")
                    }
                }
            }
        }
        mainCamera = camera
    }
}

How to start or stop recording ?#

Sample code to start and stop video recording:

/** Starts or stops video recording. */
fun toggleStartStopRecord(drone: Drone) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        component<Camera.Recording>()?.apply {
            when (state) {
                // video recording can be stopped
                Camera.Recording.State.Starting,
                is Camera.Recording.State.Started -> start()

                // video recording can be started
                is Camera.Recording.State.Stopped -> stop()

                // video recording state don't allow to start or stop
                else -> println("Video recording can't be started or stopped")
            }
        } ?: run {
            // recording component not available at present
            println("Video recording not available")
        }
    }
}