Headphone Wire Control
1. Introducing
#import <AVFoundation/AVFoundation.h>
2. Turn on remote control events
[[Avaudiosession sharedinstance] Setcategory:avaudiosessioncategoryplayback Error:nil];
if (![ [Avaudiosession sharedinstance] Setactive:yes Error:nil]) {
NSLog (@ "Failed to set up a session");
}
[[UIApplication sharedapplication] beginreceivingremotecontrolevents];
3. Call Remote Control method
-(void) Remotecontrolreceivedwithevent: (Uievent *) event {NSLog (@ "Event Type:%d, subtype:%d", Event.type, Event.subt
YPE); if (Event.type = = Uieventtyperemotecontrol) {switch (event.subtype) {case Uieventsubtyperemotecontro
Lplay:nslog (@ "Play");
Break
Case Uieventsubtyperemotecontrolpause:nslog (@ "paused");
Break
Case Uieventsubtyperemotecontrolstop:nslog (@ "Stop");
Break
Case Uieventsubtyperemotecontroltoggleplaypause:nslog (@ "suspend/stop");
Break
Case Uieventsubtyperemotecontrolnexttrack:nslog (@ "next song");
Break
Case Uieventsubtyperemotecontrolprevioustrack:nslog (@ "last song");
Break
Case Uieventsubtyperemotecontrolbeginseekingbackward:nslog (@ "Start back");
Break CASE Uieventsubtyperemotecontrolendseekingbackward:nslog (@ "End back");
Break
Case Uieventsubtyperemotecontrolbeginseekingforward:nslog (@ "start ahead");
Break
Case Uieventsubtyperemotecontrolendseekingforward:nslog (@ "End forward");
Break
Default:break; }
}
}