[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(routeChange:) name:AVAudioSessionRouteChangeNotification object:nil];
/**
监测外音变化
@param notification 通知可以得到很多信息
*/
-(void)routeChange:(NSNotification*)notification{
NSArray* outputs = [[AVAudioSession sharedInstance] currentRoute].outputs;
AVAudioSessionPortDescription* portDescription = [outputsfirstObject];
DebugLog(@"port Description:%@", portDescription);
if([portDescription.portTypeisEqualToString:@"Headphones"]) {//耳机
}elseif([portDescription.portTypeisEqualToString:@"Speaker"]) {//扬声器
[self setSpeakerButtonState:YES];
}elseif([portDescription.portTypeisEqualToString:@"Receiver"]) {//小声
[self setSpeakerButtonState:NO];
}
// }
}