iOS Development--QQ Music practice, background play and lock screen interface

Source: Internet
Author: User

I. Setting up background playback

  • Allow program background playback first
  • Code implementation
    1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {2     3     //to set the background playback code, step4     //1. Get the audio session5Avaudiosession *session =[Avaudiosession sharedinstance];6     //2. Set Background playback type7 [Session Setcategory:avaudiosessioncategoryplayback Error:nil];8     //3. Activating the session9 [Session Setactive:yes Error:nil];Ten      One     returnYES; A}

Two. Lock Screen interface

  • Appropriate time to call this method
    #pragmaMark-Set the lock screen information-(void) setuplockscreeninfo{//1. Get the song that is currently playingChaosmusic *playingmusic =[Chaosmusictool Playingmusic]; //2. Get the Lock Screen interface CenterMpnowplayinginfocenter *playingcenter =[Mpnowplayinginfocenter Defaultcenter]; //3. Setting up the display informationNsmutabledictionary *playinginfo =[Nsmutabledictionary dictionary]; Playinginfo[mpmediaitempropertyalbumtitle]=Playingmusic.name; Playinginfo[mpmediaitempropertyartist]=Playingmusic.singer; Mpmediaitemartwork*artwork =[[Mpmediaitemartwork alloc] initwithimage:[uiimage ImageNamed:playingMusic.icon]]; Playinginfo[mpmediaitempropertyartwork]=artwork; Playinginfo[mpmediaitempropertyartist]=@ (self.player.currentTime); Playingcenter.nowplayinginfo=Playinginfo; //4. Allow the application to accept remote events[[UIApplication sharedapplication] beginreceivingremotecontrolevents];}

  • Implementation of the lock screen interface, without the implementation of monitoring remote events, lock screen interface of the Next button, such as no response. Implement the following methods
    1 //listening for remote events2- (void) Remotecontrolreceivedwithevent: (Uievent *)Event3 {4     Switch(Event. Subtype) {5          CaseUieventsubtyperemotecontrolplay:6          CaseUieventsubtyperemotecontrolpause:7 [self startorpause:nil];8              Break;9             Ten          CaseUieventsubtyperemotecontrolnexttrack: One [self nextmusic:nil]; A              Break; -              -          CaseUieventsubtyperemotecontrolprevioustrack: the [self previousmusic:nil]; -              Break; -              -         default: +              Break; -     } +}

iOS Development--QQ Music practice, background play and lock screen interface

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.