播客"跳过" iOS锁屏中的按钮

时间:2015-02-06 16:26:40

标签: ios iphone xcode audio ios8

我有一个在iOS设备上播放背景音频的音频应用。我需要让应用程序有“跳过15”按钮 - 一个Apple播客应用程序和阴天 - 而不是下一个/上一个音轨按钮。有谁知道文档的位置,或者一些例子?这对谷歌来说是一个棘手的问题。

1 个答案:

答案 0 :(得分:5)

更新:对于iOS 7.1及更高版本https://stackoverflow.com/a/24818340/1469259的这个问题的答案很好。

<小时/> 锁定屏幕上的按钮触发&#34;遥控器&#34;事件。您可以根据需要处理这些事件并向前/向后跳过:

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