1, allow remote events to be accepted
[[UIApplication sharedapplication] beginreceivingremotecontrolevents];
[Self becomefirstresponder];
This sentence is important, otherwise some devices do not respond
-(BOOL) Canbecomefirstresponder {
return YES;
}
2, Handling Input events:
-(void) Remotecontrolreceivedwithevent: (uievent *) receivedevent {
if (Receivedevent.type = = Uieventtyperemotecontrol)
{
Switch (receivedevent.subtype) {
Case Uieventsubtyperemotecontroltoggleplaypause:
Do something
Break
Case Uieventsubtyperemotecontrolprevioustrack:
Do something
Break
Case Uieventsubtyperemotecontrolnexttrack:
Do something
Break
Default
Break
}
}
3, stop accepting remote events at the end of use
[[UIApplication sharedapplication] endreceivingremotecontrolevents];
[Self resignfirstresponder];
4, enclose the complete event type code for everyone to use
typedef enum {
Uieventsubtypenone = 0,
Uieventsubtypemotionshake = 1,
Uieventsubtyperemotecontrolplay = 100,
Uieventsubtyperemotecontrolpause = 101,
Uieventsubtyperemotecontrolstop = 102,
Uieventsubtyperemotecontroltoggleplaypause = 103,
Uieventsubtyperemotecontrolnexttrack = 104,
Uieventsubtyperemotecontrolprevioustrack = 105,
Uieventsubtyperemotecontrolbeginseekingbackward = 106,
Uieventsubtyperemotecontrolendseekingbackward = 107,
Uieventsubtyperemotecontrolbeginseekingforward = 108,
Uieventsubtyperemotecontrolendseekingforward = 109,
} Uieventsubtype;
Okay, so here's the use of headphone mode.