録音時間の上限
接続中のデバイスで許可される音声録音時間の上限を確認または設定します。値の単位は分です。
前提条件
- デバイスが接続済みで、操作可能な状態であること。
- デバイスが
DeviceAudioRecordingAPIに準拠していること。 - 現在値を表示する前に、
maxAudioRecordDurationがnilではないことを確認すること。
API リファレンス
フレームワーク
AIBuds.xcframework
インポート
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>プロトコル
- Swift
- Objective-C
/// The protocol for device API that supports audio recording.
protocol DeviceAudioRecordingAPI: DeviceAPI {
/// Maximum audio recording duration (in minutes) allowed by the device.
var maxAudioRecordDuration: NSNumber? { get }
/// Sets the maximum audio recording duration (in minutes) allowed by the device.
/// - Parameters:
/// - duration: The desired maximum recording duration in minutes.
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
func setMaxAudioRecordDuration(
_ duration: Int,
completion: AIBudsCompletionHandler?
)
}/// The protocol for device API that supports audio recording.
@protocol AIBudsDeviceAudioRecordingAPI <AIBudsDeviceAPI>
/// Maximum audio recording duration (in minutes) allowed by the device.
@property(nonatomic, readonly, strong) NSNumber *_Nullable maxAudioRecordDuration;
/// Sets the maximum audio recording duration (in minutes) allowed by the device.
/// - Parameters:
/// - duration: The desired maximum recording duration in minutes.
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the
/// operation was successful.
- (void)setMaxAudioRecordDuration:(NSInteger)duration
completion:(AIBudsCompletionHandler _Nullable)completion;
@endプロパティとインスタンスメソッド
| シンボル | 用途 |
|---|---|
maxAudioRecordDuration | 現在の上限(分)。取得できない場合は nil。 |
setMaxAudioRecordDuration | 録音時間の上限を分単位で設定します。 |
現在の SDK Demo では 1...120 分のスライダーを使用しています。公開 SDK では共通の有効範囲がまだ明記されていないため、この範囲は現行 Demo の仕様として扱ってください。
使用例
- Swift
- Objective-C
import AIBuds
guard let device = device as? DeviceAudioRecordingAPI else {
print("Device does not support audio recording")
return
}
if let minutes = device.maxAudioRecordDuration?.intValue {
print("Current maximum: \(minutes) minutes")
}
// 30 minutes follows the range used by the current SDK Demo.
device.setMaxAudioRecordDuration(30) { success, error in
if !success {
print(error?.localizedDescription ?? "Failed to update the duration")
}
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
id<AIBudsDeviceAudioRecordingAPI> device = (id<AIBudsDeviceAudioRecordingAPI>)self.device;
if ([device conformsToProtocol:@protocol(AIBudsDeviceAudioRecordingAPI)]) {
NSLog(@"Current maximum: %@ minutes", device.maxAudioRecordDuration);
// 30 minutes follows the range used by the current SDK Demo.
[device setMaxAudioRecordDuration:30
completion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"Failed to update the duration: %@",
error.localizedDescription);
}
}];
}エラー処理
更新に失敗した場合は、maxAudioRecordDuration から表示値を復元します。SDK は現在、対応する時間範囲を公開していません。Demo の範囲は独立して管理し、公開デバイス機能として範囲を取得できるようになった時点で置き換えてください。