我有一个音频应用程序可以在 iOS 设备上播放背景音频。我需要让应用程序具有“跳过 15”按钮(就像 Apple 播客应用程序和 Overcast)而不是下一首/上一首轨道按钮。有谁知道这方面的文档或一些示例在哪里?这对 Google 来说是一个棘手的问题。
最佳答案
更新:在 https://stackoverflow.com/a/24818340/1469259 上对 iOS 7.1 及更高版本这个问题的很好回答.
锁定屏幕上的按钮触发“远程控制”事件。您可以根据需要处理这些事件并向前/向后跳过:
- (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;
}
}
}
实际跳过的方式取决于您播放音频的方式。
实现此目标的另一种可能方法是 MPSkipIntervalCommand
https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPSkipIntervalCommand_Ref/index.html
关于ios - iOS 锁定屏幕中的播客 "skip"按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28370299/