2013-02-13 5 views
0

Je suis nouveau développeur iOS. J'essaie de faire en sorte que les boutons lecture/pause de la barre en cours de lecture (barre inférieure de l'écran d'accueil) simulent les boutons lecture/pause de mon application. toute aide s'il vous plaît.iOS AVPlayer numéro

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback 
             error:nil]; 
[[AVAudioSession sharedInstance] setActive:YES 
            error:nil]; 
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 
[self.player play]; 

UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid; 
if([player play]){ 
    newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL]; 

    bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^(void) { 
     [[UIApplication sharedApplication] endBackgroundTask: bgTask]; 
     bgTask = UIBackgroundTaskInvalid; 
    }]; 

    //Your bg code here 

    [[UIApplication sharedApplication] endBackgroundTask: bgTask]; 
    bgTask = UIBackgroundTaskInvalid; 

Répondre

0

Après avoir appelé:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 

dans votre délégué app vous recevrez des événements lorsque les boutons sont pressés ... les manipuler comme ceci:

-(void)remoteControlReceivedWithEvent:(UIEvent *)event 
{ 
    switch(event.subtype) 
    { 
     case UIEventSubtypeRemoteControlPause: 
      [player pause]; 
      break; 
     case UIEventSubtypeRemoteControlPlay: 
      [player play]; 
      break; 

    } 
} 

Et d'ajouter d'autres cas pour suivant/précédent/etc ....