有没有一种公开的方式来强制MPNowPlayingInfoCenter显示播客控件?

我希望控制中心(通过MPNowPlayingInfoCenter)显示苹果用播客显示的前进15秒/后退15秒控件,如下所示:

播客控制

完全缺乏文档告诉我,没有明显的方法来做到这一点,但是有没有人发现有任何非显而易见的方式来强制这一点,而不诉诸私人方法?

我已经得到了正确的前进/后退button的处理,我只是想使用更合适的用户界面。 任何帮助将不胜感激。

好,所以我有一点时间在我的手上,所以我跟着面包屑……这就是我发现的。

包含MediaPlayer框架并获取RemoteCommandCenter:

MPRemoteCommandCenter *rcc = [MPRemoteCommandCenter sharedCommandCenter]; 

那么如果你想按照阴云设置跳过控制,你可以执行以下操作:

 MPSkipIntervalCommand *skipBackwardIntervalCommand = [rcc skipBackwardCommand]; [skipBackwardIntervalCommand setEnabled:YES]; [skipBackwardIntervalCommand addTarget:self action:@selector(skipBackwardEvent:)]; skipBackwardIntervalCommand.preferredIntervals = @[@(42)]; // Set your own interval MPSkipIntervalCommand *skipForwardIntervalCommand = [rcc skipForwardCommand]; skipForwardIntervalCommand.preferredIntervals = @[@(42)]; // Max 99 [skipForwardIntervalCommand setEnabled:YES]; [skipForwardIntervalCommand addTarget:self action:@selector(skipForwardEvent:)]; 

并在事件处理程序做你需要做的跳过的时间间隔:

 -(void)skipBackwardEvent: (MPSkipIntervalCommandEvent *)skipEvent { NSLog(@"Skip backward by %f", skipEvent.interval); } -(void)skipForwardEvent: (MPSkipIntervalCommandEvent *)skipEvent { NSLog(@"Skip forward by %f", skipEvent.interval); } 

注意:preferredIntervals属性是一个NSArray,但我还没有想出如何额外的时间间隔可以被指挥中心利用,除非你自己做一些事情。

需要注意的是,我发现到目前为止。 当你这样做,你正在控制所有的控制,所以默认的播放和暂停button不会显示,除非你对他们做同样的事情:

 MPRemoteCommand *pauseCommand = [rcc pauseCommand]; [pauseCommand setEnabled:YES]; [pauseCommand addTarget:self action:@selector(playOrPauseEvent:)]; // MPRemoteCommand *playCommand = [rcc playCommand]; [playCommand setEnabled:YES]; [playCommand addTarget:self action:@selector(playOrPauseEvent:)]; 

(还有一个togglePlayPauseCommand被定义了,但是我不能从命令中心得到这个命令 – 虽然它是通过耳机发射的。)

其他发现:button位于左侧/中间/右侧的固定位置,所以你不能拥有(例如)previousTrack和skipBackward,因为它们都占据了左边的位置。

有seekForward / seekBackward命令需要prevTrack和nextTrack命令被触发。 当你设置了两个button,然后触发下一个/上一个button,当你拿起你的手指时,一个按住触发一个开始寻找和一个结束寻找。

  // Doesn't show unless prevTrack is enabled MPRemoteCommand *seekBackwardCommand = [rcc seekBackwardCommand]; [seekBackwardCommand setEnabled:YES]; [seekBackwardCommand addTarget:self action:@selector(seekEvent:)]; // Doesn't show unless nextTrack is enabled MPRemoteCommand *seekForwardCommand = [rcc seekForwardCommand]; [seekForwardCommand setEnabled:YES]; [seekForwardCommand addTarget:self action:@selector(seekEvent:)]; -(void) seekEvent: (MPSeekCommandEvent *) seekEvent { if (seekEvent.type == MPSeekCommandEventTypeBeginSeeking) { NSLog(@"Begin Seeking"); } if (seekEvent.type == MPSeekCommandEventTypeEndSeeking) { NSLog(@"End Seeking"); } } 

还有一个我以前没见过的反馈机制(占有左边的位置)

  MPFeedbackCommand *likeCommand = [rcc likeCommand]; [likeCommand setEnabled:YES]; [likeCommand setLocalizedTitle:@"I love it"]; // can leave this out for default [likeCommand addTarget:self action:@selector(likeEvent:)]; MPFeedbackCommand *dislikeCommand = [rcc dislikeCommand]; [dislikeCommand setEnabled:YES]; [dislikeCommand setActive:YES]; [dislikeCommand setLocalizedTitle:@"I hate it"]; // can leave this out for default [dislikeCommand addTarget:self action:@selector(dislikeEvent:)]; BOOL userPreviouslyIndicatedThatTheyDislikedThisItemAndIStoredThat = YES; if (userPreviouslyIndicatedThatTheyDislikedThisItemAndIStoredThat) { [dislikeCommand setActive:YES]; } MPFeedbackCommand *bookmarkCommand = [rcc bookmarkCommand]; [bookmarkCommand setEnabled:YES]; [bookmarkCommand addTarget:self action:@selector(bookmarkEvent:)]; // Feedback events also have a "negative" property but Command Center always returns not negative -(void)dislikeEvent: (MPFeedbackCommandEvent *)feedbackEvent { NSLog(@"Mark the item disliked"); } -(void)likeEvent: (MPFeedbackCommandEvent *)feedbackEvent { NSLog(@"Mark the item liked"); } -(void)bookmarkEvent: (MPFeedbackCommandEvent *)feedbackEvent { NSLog(@"Bookmark the item or playback position"); } 

这会显示三个水平条并显示一个警报表 – 您可以通过设置活动属性来单独突出显示这些警报表。

还有一个评级命令定义 – 但我不能得到这个显示在指挥中心

 // MPRatingCommand *ratingCommand = [rcc ratingCommand]; // [ratingCommand setEnabled:YES]; // [ratingCommand setMinimumRating:0.0]; // [ratingCommand setMaximumRating:5.0]; // [ratingCommand addTarget:self action:@selector(ratingEvent:)]; 

和一个回放速度改变命令 – 但再次无法得到这个显示在指挥中心

 // MPChangePlaybackRateCommand *playBackRateCommand = [rcc changePlaybackRateCommand]; // [playBackRateCommand setEnabled:YES]; // [playBackRateCommand setSupportedPlaybackRates:@[@(1),@(1.5),@(2)]]; // [playBackRateCommand addTarget:self action:@selector(remoteControlReceivedWithEvent:)]; 

如果你愿意的话,还有一个基于块的目标行动机制

 // @property (strong, nonatomic) id likeHandler; self.likeHandler = [likeCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) { NSLog(@"They like it"); return MPRemoteCommandHandlerStatusSuccess; // or fail or no such content }]; 

最后一点要注意的是:如果你已经通过[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]注册接收远程事件; 那么这些命令中的一些还会触发 – (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent处理程序中的事件。 这些是UIEvents,虽然typesUIEventTypeRemoteControl和一个子types来区分事件。 你不能在这个方法中将这些与MPRemoteCommandEvents混合和匹配。 有一些提示MPRemoteCommandEvents将在某些时候replaceUIEvents。

所有这些基于试验和错误,所以随时纠正。

加雷思

反馈命令和skipforward的屏幕截图

苹果没有文件,因为没有办法改变这一点。 再次,苹果保持最好的东西(Siri也想到了)。

越狱版本支持更改控制中心button,我在这个网站上find。 我有一种感觉,你想在实际的 iOS 7上使用这个应用程序,而不是一个越狱版本,所以这根本不帮你。

这些私人API太频繁地妨碍开发好的应用程序。 除非苹果给我们更多的自由来使用当前私有的API,否则你是不走运的。

Oooooooh。 Marco Arment得到了这个在阴暗的工作,至less给这个卡特罗的家伙留下了一条面包屑path:

这是MPRemoteCommandCenter。 不过,祝你好运。

以下是所有关注这个问题的人所说的文档 – 我猜测它与skipBackwardCommandskipForwardCommand 。 我没有时间仔细研究它,所以我会把这个留在这里,以防有人想捅它,给出更彻底的答案。

对于Swift开发人员

 import MediaPlayer let rcc = MPRemoteCommandCenter.shared() let skipBackwardCommand = rcc.skipBackwardCommand skipBackwardCommand.isEnabled = true skipBackwardCommand.addTarget(handler: skipBackward) skipBackwardCommand.preferredIntervals = [42] let skipForwardCommand = rcc.skipForwardCommand skipForwardCommand.isEnabled = true skipForwardCommand.addTarget(handler: skipForward) skipForwardCommand.preferredIntervals = [42] func skipBackward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus { guard let command = event.command as? MPSkipIntervalCommand else { return .noSuchContent } let interval = command.preferredIntervals[0] print(interval) //Output: 42 return .success } func skipForward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus { guard let command = event.command as? MPSkipIntervalCommand else { return .noSuchContent } let interval = command.preferredIntervals[0] print(interval) //Output: 42 return .success } 

其他命令将是类似的,他们可以在这里检查

Interesting Posts