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

Side by Side Diff: webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm

Issue 2366753005: Adds support for AVAudioSessionSilenceSecondaryAudioHintNotification on iOS (Closed)
Patch Set: Feedback from tkchin@ Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; 60 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
61 [center addObserver:self 61 [center addObserver:self
62 selector:@selector(handleInterruptionNotification:) 62 selector:@selector(handleInterruptionNotification:)
63 name:AVAudioSessionInterruptionNotification 63 name:AVAudioSessionInterruptionNotification
64 object:nil]; 64 object:nil];
65 [center addObserver:self 65 [center addObserver:self
66 selector:@selector(handleRouteChangeNotification:) 66 selector:@selector(handleRouteChangeNotification:)
67 name:AVAudioSessionRouteChangeNotification 67 name:AVAudioSessionRouteChangeNotification
68 object:nil]; 68 object:nil];
69 // TODO(tkchin): Maybe listen to SilenceSecondaryAudioHintNotification.
70 [center addObserver:self 69 [center addObserver:self
71 selector:@selector(handleMediaServicesWereLost:) 70 selector:@selector(handleMediaServicesWereLost:)
72 name:AVAudioSessionMediaServicesWereLostNotification 71 name:AVAudioSessionMediaServicesWereLostNotification
73 object:nil]; 72 object:nil];
74 [center addObserver:self 73 [center addObserver:self
75 selector:@selector(handleMediaServicesWereReset:) 74 selector:@selector(handleMediaServicesWereReset:)
76 name:AVAudioSessionMediaServicesWereResetNotification 75 name:AVAudioSessionMediaServicesWereResetNotification
77 object:nil]; 76 object:nil];
77 // Posted on the main thread when the primary audio from other applications
78 // starts and stops. Foreground applications may use this notification as a
79 // hint to enable or disable audio that is secondary.
80 [center addObserver:self
81 selector:@selector(handleSilenceSecondaryAudioHintNotification:)
82 name:AVAudioSessionSilenceSecondaryAudioHintNotification
83 object:nil];
78 // Also track foreground event in order to deal with interruption ended situ ation. 84 // Also track foreground event in order to deal with interruption ended situ ation.
79 [center addObserver:self 85 [center addObserver:self
80 selector:@selector(handleApplicationDidBecomeActive:) 86 selector:@selector(handleApplicationDidBecomeActive:)
81 name:UIApplicationDidBecomeActiveNotification 87 name:UIApplicationDidBecomeActiveNotification
82 object:nil]; 88 object:nil];
83 } 89 }
84 return self; 90 return self;
85 } 91 }
86 92
87 - (void)dealloc { 93 - (void)dealloc {
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 [self updateAudioSessionAfterEvent]; 515 [self updateAudioSessionAfterEvent];
510 [self notifyMediaServicesWereLost]; 516 [self notifyMediaServicesWereLost];
511 } 517 }
512 518
513 - (void)handleMediaServicesWereReset:(NSNotification *)notification { 519 - (void)handleMediaServicesWereReset:(NSNotification *)notification {
514 RTCLog(@"Media services were reset."); 520 RTCLog(@"Media services were reset.");
515 [self updateAudioSessionAfterEvent]; 521 [self updateAudioSessionAfterEvent];
516 [self notifyMediaServicesWereReset]; 522 [self notifyMediaServicesWereReset];
517 } 523 }
518 524
525 - (void)handleSilenceSecondaryAudioHintNotification:(NSNotification *)notificati on {
526 // TODO(henrika): just adding logs here for now until we know if we are ever
527 // see this notification and might be affected by it or if further actions
528 // are required.
529 NSNumber *typeNumber =
530 notification.userInfo[AVAudioSessionSilenceSecondaryAudioHintTypeKey];
531 AVAudioSessionSilenceSecondaryAudioHintType type =
532 (AVAudioSessionSilenceSecondaryAudioHintType)typeNumber.unsignedIntegerVal ue;
533 switch (type) {
534 case AVAudioSessionSilenceSecondaryAudioHintTypeBegin:
535 RTCLog(@"Another application's primary audio has started.");
536 break;
537 case AVAudioSessionSilenceSecondaryAudioHintTypeEnd:
538 RTCLog(@"Another application's primary audio has stopped.");
539 break;
540 }
541 }
542
519 - (void)handleApplicationDidBecomeActive:(NSNotification *)notification { 543 - (void)handleApplicationDidBecomeActive:(NSNotification *)notification {
520 if (self.isInterrupted) { 544 if (self.isInterrupted) {
521 RTCLog(@"Application became active after an interruption. Treating as interr uption end."); 545 RTCLog(@"Application became active after an interruption. Treating as interr uption end.");
522 self.isInterrupted = NO; 546 self.isInterrupted = NO;
523 [self updateAudioSessionAfterEvent]; 547 [self updateAudioSessionAfterEvent];
524 [self notifyDidEndInterruptionWithShouldResumeSession:YES]; 548 [self notifyDidEndInterruptionWithShouldResumeSession:YES];
525 } 549 }
526 } 550 }
527 551
528 #pragma mark - Private 552 #pragma mark - Private
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 - (void)notifyDidStopPlayOrRecord { 847 - (void)notifyDidStopPlayOrRecord {
824 for (auto delegate : self.delegates) { 848 for (auto delegate : self.delegates) {
825 SEL sel = @selector(audioSessionDidStopPlayOrRecord:); 849 SEL sel = @selector(audioSessionDidStopPlayOrRecord:);
826 if ([delegate respondsToSelector:sel]) { 850 if ([delegate respondsToSelector:sel]) {
827 [delegate audioSessionDidStopPlayOrRecord:self]; 851 [delegate audioSessionDidStopPlayOrRecord:self];
828 } 852 }
829 } 853 }
830 } 854 }
831 855
832 @end 856 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698