跳到主要内容

录像

请求已连接设备开始或停止录像。

前置条件

API 参考

协议

Swift
/// The protocol for device API that supports camera.
protocol DeviceCameraAPI: DeviceAPI {
    /// Requests to start video recording.
    /// - Parameters:
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - statusCode: The status code returned by the device. `nil` if the operation failed.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func requestVideoRecording(_ completion: AIBudsStatusCodeCompletionHandler?)

    /// Requests to stop the current video recording session.
    /// - Parameters:
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - statusCode: The status code returned by the device. `nil` if the operation failed.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func requestStopVideoRecording(_ completion: AIBudsStatusCodeCompletionHandler?)
}
方法用途
requestVideoRecording开始录像。
requestStopVideoRecording停止录像。

使用示例

Swift
guard let device = device as? DeviceCameraAPI else { return }

device.requestVideoRecording { success, statusCode, error in
    guard success else {
        print(error?.localizedDescription ?? "Video recording failed to start")
        return
    }
    print("Video recording started: \(statusCode?.stringValue ?? "Unavailable")")
}

device.requestStopVideoRecording { success, _, error in
    if !success { print(error?.localizedDescription ?? "Video recording failed to stop") }
}

回调报告设备命令状态,不返回视频路径或分辨率。当前公开 API 不提供按请求选择分辨率的能力。