2013-02-13 87 views
0

我是新的iOS开发人员。 我正在尝试使现在播放栏(主屏幕底部栏)中的播放/暂停按钮模拟我的应用程序中的播放/暂停按钮。 请任何帮助。iOS AVPlayer问题

[[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; 

回答

0

调用后:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 
在应用程序委托

您将收到事件时按下按钮...处理它们是这样的:

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

    } 
} 

而对于添加其他案件next/prev/etc ...