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