作者:mobiledu2502861417 | 来源:互联网 | 2023-05-23 10:07
我有一个在iOS设备上播放背景音频的音频应用.我需要让应用程序有"跳过15"按钮 - 一个Apple播客应用程序和阴天 - 而不是下一个/上一个音轨按钮.有谁知道文档的位置,或者一些例子?这对谷歌来说是一个棘手的问题.
1> CupawnTae..:
更新:iOS 7.1及更高版本的这个问题很好的答案,请访问/sf/ask/17360801/.
锁定屏幕上的按钮触发"远程控制"事件.您可以根据需要处理这些事件并向前/向后跳过:
- (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