メインコンテンツまでスキップ

動画を録画

接続中のデバイスへ動画録画の開始または停止を要求します。

前提条件

  • デバイスが接続済みで、空き容量があり、DeviceCameraAPI に準拠していること。

API Reference

プロトコル

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 では、要求ごとに解像度を選択できません。