IOS: Remote Control of Multimedia

Source: Internet
Author: User

Remote-control

Users can use external interfaces to control application music. The official recommendation is to receive remote-control events when the view is displayed.

 

-(Void) viewdidappear :( bool) animated <br/>{< br/> [Super viewdidappear: animated]; <br/> [[uiapplication sharedapplication] beginreceivingremotecontrolevents]; <br/> [self becomefirstresponder]; <br/>} 

 

Then, when the view disappears, the remote-control event is canceled.

-(Void) viewwilldisappear :( bool) animated <br/>{< br/> [Super viewwilldisappear: animated]; <br/> [[uiapplication sharedapplication] endreceivingremotecontrolevents]; <br/> [self resignfirstresponder]; <br/>} 

Another point is that the RESP receiving reomte-control must be first responder, so canbecamefirstresponder must be rewritten.

-(Bool) canbecomefirstresponder <br/>{< br/> return yes; <br/>} 

 

Another simple method is to derive a uiwindow and rewrite its-(void) remotecontrolreceivedwithevent: (uievent *) receivedevent Method

 

-(Void) remotecontrolincluedwithevent: (uievent *) receivedevent {</P> <p> If (receivedevent. type = uieventtyperemotecontrol) {</P> <p> switch (receivedevent. subtype) {</P> <p> case uieventsubtyperemotecontroltoggleplaypause: <br/> [self playorstop: Nil]; <br/> break; </P> <p> case uieventsubtyperemotecontrolprevioustrack: <br/> [self previoustrack: Nil]; <br/> break; </P> <p> case uieventsubtyperemotecontrolnexttrack: <br/> [self nexttrack: Nil]; <br/> break; </P> <p> default: <br/> break; <br/>}< br/>} 

 

Is it simpler ?!

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.