@@ -114,7 +114,7 @@ - (instancetype)initWithAudioSession:(id)audioSession {
114
114
options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
115
115
context: (__bridge void *)RTC_OBJC_TYPE (RTCAudioSession).class ];
116
116
117
- self. isRecordingEnabled = [_session.category isEqualToString: AVAudioSessionCategoryPlayAndRecord ];
117
+ _isRecordingEnabled = [self sessionCategoryIsRecordingEnabled ];
118
118
119
119
RTCLog (@" RTC_OBJC_TYPE(RTCAudioSession) (%p ): init." , self);
120
120
}
@@ -542,14 +542,13 @@ - (void)handleRouteChangeNotification:(NSNotification *)notification {
542
542
RTCLog (@" Audio route changed: OldDeviceUnavailable" );
543
543
break ;
544
544
case AVAudioSessionRouteChangeReasonCategoryChange:
545
- RTCLog (@" Audio route changed: CategoryChange to :%@ " ,
546
- self.session .category );
547
- if (!self.isRecordingEnabled && [self .session.category isEqualToString: AVAudioSessionCategoryPlayAndRecord]) {
548
- self.isRecordingEnabled = true ;
549
- [self notifyWillRecord ];
550
- }
551
- if (self.isRecordingEnabled && [self .session.category isEqualToString: AVAudioSessionCategoryPlayback]) {
552
- self.isRecordingEnabled = false ;
545
+ RTCLog (@" Audio route changed: CategoryChange to :%@ " , self.session .category );
546
+ {
547
+ BOOL newValue = [self sessionCategoryIsRecordingEnabled ];
548
+ if (_isRecordingEnabled != newValue) {
549
+ _isRecordingEnabled = newValue;
550
+ [self notifyDidChangeAudioSessionRecordingEnabled ];
551
+ }
553
552
}
554
553
break ;
555
554
case AVAudioSessionRouteChangeReasonOverride:
@@ -782,7 +781,7 @@ - (BOOL)unconfigureWebRTCSession:(NSError **)outError {
782
781
}
783
782
RTCLog (@" Unconfiguring audio session for WebRTC." );
784
783
[self setActive: NO error: outError];
785
- self. isRecordingEnabled = NO ;
784
+ _isRecordingEnabled = NO ;
786
785
787
786
return YES ;
788
787
}
@@ -1007,14 +1006,18 @@ - (void)notifyFailedToSetActive:(BOOL)active error:(NSError *)error {
1007
1006
}
1008
1007
}
1009
1008
1010
- - (void )notifyWillRecord {
1009
+ - (void )notifyDidChangeAudioSessionRecordingEnabled {
1011
1010
for (auto delegate : self.delegates ) {
1012
- SEL sel = @selector (audioSessionWillRecord : );
1011
+ SEL sel = @selector (audioSessionDidChangeRecordingEnabled : );
1013
1012
if ([delegate respondsToSelector: sel]) {
1014
- [delegate audioSessionWillRecord :self ];
1013
+ [delegate audioSessionDidChangeRecordingEnabled :self ];
1015
1014
}
1016
1015
}
1017
1016
}
1018
1017
1018
+ -(BOOL )sessionCategoryIsRecordingEnabled {
1019
+ return [_session.category isEqualToString: AVAudioSessionCategoryPlayAndRecord] ||
1020
+ [_session.category isEqualToString: AVAudioSessionCategoryRecord];
1021
+ }
1019
1022
1020
1023
@end
0 commit comments