AVAudioSessionRoute中断后继续更改

时间:2018-07-06 14:06:05

标签: ios objective-c

我正在将音频播放器的一部分与播放选项一起使用,但是当它被另一个应用程序(例如电话)中断时,播放器会在中断结束后反复发出小声和短声。

我以为插入耳机并用AVAudioSessionRouteChangeNotification检查当前路线时听起来像是杂音。

2018-07-06 22:14:30.848495+0900 Interruption End
2018-07-06 22:14:30.853979+0900 route change?
routeChangeReason: Override
Current input: (null)
Current output: (null)
2018-07-06 22:14:31.077595+0900 route change?
routeChangeReason: CategoryChange
Current input: MicrophoneBuiltIn
Current output: Speaker
2018-07-06 22:14:31.157107+0900 route change?
routeChangeReason: Override
Current input: (null)
Current output: (null)
2018-07-06 22:14:31.428088+0900 route change?
routeChangeReason: CategoryChange
Current input: MicrophoneBuiltIn
Current output: Speaker
2018-07-06 22:14:31.509741+0900 route change?
routeChangeReason: Override
Current input: (null)
Current output: (null)
...

我试图通过AVAudioSessionInterruptionNotification处理程序来解决,该处理程序暂停AVAudioPlayer或停用AVAudioSession实例,但这无济于事。

- (void)audioSessionInterruptionHandler:(NSNotification*)notification {
   NSDictionary *userInfo = notification.userInfo;
   NSNumber *type = [userInfo valueForKey:AVAudioSessionInterruptionTypeKey];
  if ([type intValue] == AVAudioSessionInterruptionTypeBegan) {
      NSLog(@"Interruption Start");
      // [self pause];
      // [[[AVAudioSession] sharedInstance] setActive:NO];
  } else {
      NSLog(@"Interruption End");
  }
}

处理此问题的正确方法是什么?

0 个答案:

没有答案