1、獲取耳機(jī)插拔事件Key
AVAudioSessionRouteChangeNotification
2、耳機(jī)控制鍵
首先允許遠(yuǎn)程控制
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
實(shí)現(xiàn)
//received remote event
-(void)remoteControlReceivedWithEvent:(UIEvent *)event{
if (event.type == UIEventTypeRemoteControl) {
switch (event.subtype) {
case UIEventSubtypeRemoteControlPlay:{
NSLog(@"play---------");
}break;
case UIEventSubtypeRemoteControlPause:{
NSLog(@"Pause---------");
}break;
case UIEventSubtypeRemoteControlStop:{
NSLog(@"Stop---------");
}break;
case UIEventSubtypeRemoteControlTogglePlayPause:{
//單擊暫停鍵:103
NSLog(@"單擊暫停鍵:103");
}break;
case UIEventSubtypeRemoteControlNextTrack:{
//雙擊暫停鍵:104
NSLog(@"雙擊暫停鍵:104");
}break;
case UIEventSubtypeRemoteControlPreviousTrack:{
NSLog(@"三擊暫停鍵:105");
}break;
case UIEventSubtypeRemoteControlBeginSeekingForward:{
NSLog(@"單擊,再按下不放:108");
}break;
case UIEventSubtypeRemoteControlEndSeekingForward:{
NSLog(@"單擊,再按下不放,松開(kāi)時(shí):109");
}break;
default:
break;
}
}
}