Adds support for AVAudioSessionSilenceSecondaryAudioHintNotification on iOS

BUG=b/30944297
NOTRY=TRUE

Review-Url: https://codereview.webrtc.org/2366753005
Cr-Commit-Position: refs/heads/master@{#14398}
This commit is contained in:
henrika
2016-09-27 06:06:44 -07:00
committed by Commit bot
parent 46a8d18efa
commit f1363fdf57

View File

@ -66,7 +66,6 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
selector:@selector(handleRouteChangeNotification:)
name:AVAudioSessionRouteChangeNotification
object:nil];
// TODO(tkchin): Maybe listen to SilenceSecondaryAudioHintNotification.
[center addObserver:self
selector:@selector(handleMediaServicesWereLost:)
name:AVAudioSessionMediaServicesWereLostNotification
@ -75,6 +74,13 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
selector:@selector(handleMediaServicesWereReset:)
name:AVAudioSessionMediaServicesWereResetNotification
object:nil];
// Posted on the main thread when the primary audio from other applications
// starts and stops. Foreground applications may use this notification as a
// hint to enable or disable audio that is secondary.
[center addObserver:self
selector:@selector(handleSilenceSecondaryAudioHintNotification:)
name:AVAudioSessionSilenceSecondaryAudioHintNotification
object:nil];
// Also track foreground event in order to deal with interruption ended situation.
[center addObserver:self
selector:@selector(handleApplicationDidBecomeActive:)
@ -516,6 +522,24 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2;
[self notifyMediaServicesWereReset];
}
- (void)handleSilenceSecondaryAudioHintNotification:(NSNotification *)notification {
// TODO(henrika): just adding logs here for now until we know if we are ever
// see this notification and might be affected by it or if further actions
// are required.
NSNumber *typeNumber =
notification.userInfo[AVAudioSessionSilenceSecondaryAudioHintTypeKey];
AVAudioSessionSilenceSecondaryAudioHintType type =
(AVAudioSessionSilenceSecondaryAudioHintType)typeNumber.unsignedIntegerValue;
switch (type) {
case AVAudioSessionSilenceSecondaryAudioHintTypeBegin:
RTCLog(@"Another application's primary audio has started.");
break;
case AVAudioSessionSilenceSecondaryAudioHintTypeEnd:
RTCLog(@"Another application's primary audio has stopped.");
break;
}
}
- (void)handleApplicationDidBecomeActive:(NSNotification *)notification {
if (self.isInterrupted) {
RTCLog(@"Application became active after an interruption. Treating as interruption end.");