iOS 锁定屏幕中的播客 "skip" 按钮

podcast "skip" buttons in iOS lock screen

我有一个音频应用程序可以在 iOS 设备上播放背景音频。我需要让应用程序具有 "skip 15" 按钮——就像 Apple 播客应用程序和 Overcast——而不是 next/previous 曲目按钮。有谁知道这方面的文档或一些示例在哪里?这对 Google 来说是一个棘手的问题。

更新:iOS 7.1 及更高版本 对这个问题的很好回答。


锁屏按钮触发 "remote control" 事件。您可以处理这些事件并根据需要跳过 forward/back:

- (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

可能是另一种实现此目的的方法,但我自己没有使用过 MPSkipIntervalCommand https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPSkipIntervalCommand_Ref/index.html