diff --git a/sdk/objc/components/audio/RTCAudioSession+Configuration.mm b/sdk/objc/components/audio/RTCAudioSession+Configuration.mm index 449f31e9dd..4bf0a542e1 100644 --- a/sdk/objc/components/audio/RTCAudioSession+Configuration.mm +++ b/sdk/objc/components/audio/RTCAudioSession+Configuration.mm @@ -49,43 +49,17 @@ // everything we can. NSError *error = nil; - if (self.category != configuration.category || + if (self.category != configuration.category || self.mode != configuration.mode || self.categoryOptions != configuration.categoryOptions) { - NSError *categoryError = nil; + NSError *configuringError = nil; if (![self setCategory:configuration.category - withOptions:configuration.categoryOptions - error:&categoryError]) { - RTCLogError(@"Failed to set category: %@", - categoryError.localizedDescription); - error = categoryError; + mode:configuration.mode + options:configuration.categoryOptions + error:&configuringError]) { + RTCLogError(@"Failed to set category and mode: %@", configuringError.localizedDescription); + error = configuringError; } else { - RTCLog(@"Set category to: %@", configuration.category); - } - } - - if (self.mode != configuration.mode) { - NSError *modeError = nil; - if (![self setMode:configuration.mode error:&modeError]) { - RTCLogError(@"Failed to set mode: %@", - modeError.localizedDescription); - error = modeError; - } else { - RTCLog(@"Set mode to: %@", configuration.mode); - } - } - - // Sometimes category options don't stick after setting mode. - if (self.categoryOptions != configuration.categoryOptions) { - NSError *categoryError = nil; - if (![self setCategory:configuration.category - withOptions:configuration.categoryOptions - error:&categoryError]) { - RTCLogError(@"Failed to set category options: %@", - categoryError.localizedDescription); - error = categoryError; - } else { - RTCLog(@"Set category options to: %ld", - (long)configuration.categoryOptions); + RTCLog(@"Set category to: %@, mode: %@", configuration.category, configuration.mode); } } diff --git a/sdk/objc/components/audio/RTCAudioSession.h b/sdk/objc/components/audio/RTCAudioSession.h index 3b83b27ba5..729b5a2126 100644 --- a/sdk/objc/components/audio/RTCAudioSession.h +++ b/sdk/objc/components/audio/RTCAudioSession.h @@ -225,6 +225,10 @@ RTC_OBJC_EXPORT // AVAudioSession. `lockForConfiguration` must be called before using them // otherwise they will fail with kRTCAudioSessionErrorLockRequired. +- (BOOL)setCategory:(NSString *)category + mode:(NSString *)mode + options:(AVAudioSessionCategoryOptions)options + error:(NSError **)outError; - (BOOL)setCategory:(NSString *)category withOptions:(AVAudioSessionCategoryOptions)options error:(NSError **)outError; diff --git a/sdk/objc/components/audio/RTCAudioSession.mm b/sdk/objc/components/audio/RTCAudioSession.mm index 550a426d36..2a6a2022ea 100644 --- a/sdk/objc/components/audio/RTCAudioSession.mm +++ b/sdk/objc/components/audio/RTCAudioSession.mm @@ -407,6 +407,16 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false; return success; } +- (BOOL)setCategory:(NSString *)category + mode:(NSString *)mode + options:(AVAudioSessionCategoryOptions)options + error:(NSError **)outError { + if (![self checkLock:outError]) { + return NO; + } + return [self.session setCategory:category mode:mode options:options error:outError]; +} + - (BOOL)setCategory:(NSString *)category withOptions:(AVAudioSessionCategoryOptions)options error:(NSError **)outError {