iOS program supports headphone line control

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.