Index: webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm |
diff --git a/webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm b/webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm |
index 84cc6da4e436d566c007461912cd183bc3b3a9bf..648ceac423097d6035c21272fbaee767570e6ade 100644 |
--- a/webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm |
+++ b/webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm |
@@ -24,6 +24,7 @@ |
NSString * const kRTCAudioSessionErrorDomain = @"org.webrtc.RTCAudioSession"; |
NSInteger const kRTCAudioSessionErrorLockRequired = -1; |
NSInteger const kRTCAudioSessionErrorConfiguration = -2; |
+NSString * const kRTCAudioSessionOutputVolumeSelector = @"outputVolume"; |
// This class needs to be thread-safe because it is accessed from many threads. |
// TODO(tkchin): Consider more granular locking. We're not expecting a lot of |
@@ -86,6 +87,12 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2; |
selector:@selector(handleApplicationDidBecomeActive:) |
name:UIApplicationDidBecomeActiveNotification |
object:nil]; |
+ |
tkchin_webrtc
2017/05/25 20:24:33
nit: remove blank lines
|
+ [_session addObserver:self |
+ forKeyPath:kRTCAudioSessionOutputVolumeSelector |
+ options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld |
+ context:nil]; |
+ |
RTCLog(@"RTCAudioSession (%p): init.", self); |
} |
return self; |
@@ -93,6 +100,7 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2; |
- (void)dealloc { |
[[NSNotificationCenter defaultCenter] removeObserver:self]; |
+ [_session removeObserver:self forKeyPath:kRTCAudioSessionOutputVolumeSelector context:nil]; |
RTCLog(@"RTCAudioSession (%p): dealloc.", self); |
} |
@@ -803,6 +811,18 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2; |
[self decrementActivationCount]; |
} |
+- (void)observeValueForKeyPath:(NSString *)keyPath |
+ ofObject:(id)object |
+ change:(NSDictionary *)change |
+ context:(void *)context { |
+ if (object == _session) { |
+ NSNumber *newVolume = change[NSKeyValueChangeNewKey]; |
+ [self notifyAudioVolumeDidChange:newVolume]; |
tkchin_webrtc
2017/05/25 20:24:32
notifyOutputVolumeDidChange
also, pass the float d
|
+ } else { |
+ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; |
+ } |
+} |
+ |
- (void)notifyDidBeginInterruption { |
for (auto delegate : self.delegates) { |
SEL sel = @selector(audioSessionDidBeginInterruption:); |
@@ -880,4 +900,13 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2; |
} |
} |
+- (void)notifyAudioVolumeDidChange:(NSNumber *)volume { |
+ for (auto delegate : self.delegates) { |
+ SEL sel = @selector(audioVolumeDidChange:); |
+ if ([delegate respondsToSelector:sel]) { |
+ [delegate audioVolumeDidChange:volume.floatValue]; |
+ } |
+ } |
+} |
+ |
@end |