2013-02-13 79 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 ...