Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm

Issue 2895263006: Add observer for AVAudioSession.outputVolume (Closed)
Patch Set: Method rename and cleanup. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..763f1fae54d4b41f4679e4dcbba16702d6284dfb 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,11 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
selector:@selector(handleApplicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
+ [_session addObserver:self
+ forKeyPath:kRTCAudioSessionOutputVolumeSelector
+ options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
+ context:nil];
+
RTCLog(@"RTCAudioSession (%p): init.", self);
}
return self;
@@ -93,6 +99,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 +810,22 @@ 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];
+ RTCLog(@"OutputVolumeDidChange to %f", newVolume.floatValue);
+ [self notifyDidChangeOutputVolume:newVolume.floatValue];
+ } else {
+ [super observeValueForKeyPath:keyPath
+ ofObject:object
+ change:change
+ context:context];
+ }
+}
+
- (void)notifyDidBeginInterruption {
for (auto delegate : self.delegates) {
SEL sel = @selector(audioSessionDidBeginInterruption:);
@@ -880,4 +903,13 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
}
}
+- (void)notifyDidChangeOutputVolume:(float)volume {
+ for (auto delegate : self.delegates) {
+ SEL sel = @selector(audioSession:didChangeOutputVolume:);
+ if ([delegate respondsToSelector:sel]) {
+ [delegate audioSession:self didChangeOutputVolume:volume];
+ }
+ }
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698