2015-02-06 42 views
2

我有一個在iOS設備上播放背景音頻的音頻應用程序。我需要讓應用程序具有「跳過15個」按鈕 - Apple Podcasts應用程序和Overcast--而不是下一個/上一個曲目按鈕。有沒有人知道這是什麼文件,或一些例子?這對谷歌來說是一個棘手的問題。在iOS鎖屏中播客的「跳過」按鈕

+0

最佳答案爲iOS 7.1+這裏:有沒有一種公開的方式,迫使MPNowPlayingInfoCenter到顯示播客控制?](http://stackoverflow.com/questions/20591156/is-there-a-public-way-to-force-mpnowplayinginfocenter-to-show-podcast-controls) – CupawnTae 2015-10-20 22:29:04

回答

5

更新:iOS 7.1及更高版本的這個問題的最佳答案,在https://stackoverflow.com/a/24818340/1469259


鎖定屏幕上的按鈕觸發「遠程控制」事件。您可以處理這些事件並根據需要跳過前進/後退:

- (void)viewDidAppear:(BOOL)animated { 
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 
    if ([self canBecomeFirstResponder]) { 
     [self becomeFirstResponder]; 
    } 
} 

- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent { 
    if (receivedEvent.type == UIEventTypeRemoteControl) { 
     switch (receivedEvent.subtype) { 
      case UIEventSubtypeRemoteControlTogglePlayPause: 
       // add code here to play/pause audio 
       break; 

      case UIEventSubtypeRemoteControlPreviousTrack: 
       // add code here to skip back 15 seconds 
       break; 

      case UIEventSubtypeRemoteControlNextTrack: 
       // add code here to skip forward 15 seconds 
       break; 

      default: 
       break; 
     } 
    } 
} 

實際跳過的方式取決於您如何播放音頻。

文檔在這裏https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/Remote-ControlEvents/Remote-ControlEvents.html

潛在的我用我自己實現這一目標的另一種方式,但不是一個MPSkipIntervalCommandhttps://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPSkipIntervalCommand_Ref/index.html