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:

/// Keep reference on MainCamera peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera>?

/// Monitors and prints video recording state.
func monitorRecordingState(drone: Drone) {
    cameraRef = drone.getPeripheral(Peripherals.mainCamera) { camera in
        if let camera = camera {
            let recordingState = camera.recordingState
            switch recordingState.functionState {
            case .unavailable:
                print("Video recording not available at present")
            case .stopped:
                print("Video recording stopped")
            case .starting:
                print("Video recording starting")
            case .started:
                let duration = recordingState.getDuration()
                print("Video recording started, duration: \(duration)s")
            case .stopping:
                print("Video recording stopping")
            case .errorInternal, .errorInsufficientStorageSpace, .errorInsufficientStorageSpeed:
                print("Video recording error: \(recordingState.functionState)")
            case .stoppedForReconfiguration:
                print("Video recording stopped for internal reconfiguration")
            }
            if let mediaId = recordingState.mediaId {
                print("Identifier of latest saved media: \(mediaId)")
            }
        }
    }
}

Example of output:

Video recording stopped
Video recording starting
Video recording started, duration: 0.0s
Video recording started, duration: 1.0s
Video recording started, duration: 2.0s
Video recording stopping
Video recording stopped
Identifier of latest saved media: 10000558

Camera 2#

Video recording state is monitored with sub-component Camera2Components.recording.

Sample code to monitor video recording state:

/// Keep reference on Camera2Recording component to get notified of changes.
private var recordingRef: Ref<Camera2Recording>?

/// Monitors and prints video recording state.
func monitorRecordingState(drone: Drone) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
        // get recording component reference and register listener
        recordingRef = camera.getComponent(Camera2Components.recording) { [weak self] recording in
            if let recording = recording {
                // print recording state
                self?.printRecordingState(state: recording.state)
            } else {
                // recording component nil, meaning recording is unavailable
                print("Video recording not available at present")
            }
        }
    }
}

/// Prints video recording state.
func printRecordingState(state: Camera2RecordingState) {
    switch state {
    case .stopped(let latestSavedMediaId):
        print("Video recording stopped")
        if let mediaId = latestSavedMediaId {
            print("Identifier of latest saved media: \(mediaId)")
        }
    case .starting:
        print("Video recording starting")
    case .started(let startTime, let videoBitrate, let mediaStorage):
        print("Video recording started \(videoBitrate) \(mediaStorage) \(startTime)")
    case .stopping(let reason, let savedMediaId):
        print("Video recording stopping \(reason)")
        if let mediaId = savedMediaId {
            print("Identifier of saved media: \(mediaId)")
        }
    }
}

Example of output:

Video recording stopped
Video recording starting
Video recording started 200000000 Optional(internal) 2021-02-03 10:48:50 +0000
Video recording stopping userRequest
Identifier of saved media: 10000092
Video recording stopped
Identifier of latest saved media: 10000092