최대 오디오 녹음 시간
연결된 기기에서 허용하는 최대 오디오 녹음 시간을 읽거나 설정합니다. SDK에서 사용하는 단위는 분입니다.
사전 요구 사항
- 기기가 연결되어 사용할 수 있는 상태입니다.
- 기기가
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 범위를 별도 상수로 관리하고 공식 기기 지원 값이 제공되면 교체하세요.