Maximum Recording Duration
Read or set the maximum audio recording duration allowed by the connected device. The SDK expresses this value in minutes.
Prerequisites
- The device is connected and ready.
- The device conforms to
DeviceAudioRecordingAPI. maxAudioRecordDurationis notnilbefore showing an existing value.
API Reference
Framework
AIBuds.xcframework
Import
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protocol
- 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;
@endProperty and Instance Method
| Symbol | Purpose |
|---|---|
maxAudioRecordDuration | Current maximum duration in minutes, or nil when unavailable. |
setMaxAudioRecordDuration | Set the maximum duration in minutes. |
The current SDK Demo uses a 1...120 minute slider. The public SDK does not yet document a universal legal range, so treat those limits as the current Demo convention.
Usage Examples
- 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);
}
}];
}Error Handling
If the update fails, restore the displayed value from maxAudioRecordDuration. The SDK currently does not publish the supported duration range, so keep the Demo range isolated and replace it when a public device capability becomes available.