我的应用程序不支持回到以前的曲目,我想知道我是否可以告诉锁屏音乐控件以隐藏其倒带/上一个曲目按钮。我使用MPNowPlayingInfoCenter
将这些信息传达给锁定屏幕。
非常简单的问题,可以做到吗?例如,仅显示播放/暂停,然后跳过?
从iOS 7.1开始,有一种方法可以自定义锁定屏幕和命令中心中可用的控件(以及许多其他附件): MPRemoteCommandCenter
。
关于您的问题,您可以执行以下操作:
[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand.enabled = NO;
[MPRemoteCommandCenter sharedCommandCenter].skipBackwardCommand.enabled = NO;
[MPRemoteCommandCenter sharedCommandCenter].seekBackwardCommand.enabled = NO;
// You must also register for any other command in order to take control
// of the command center, or else disabling other commands does not work.
// For example:
[MPRemoteCommandCenter sharedCommandCenter].playCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].playCommand addTarget:self action:@selector(play)];
请参阅此堆栈溢出答案,以获取有关MpremoteCommandCenter的更多一般信息。
过时:
我认为简短的答案是否定的。文档说 -
"您无法直接控制显示哪些信息或其格式。您根据要向系统提供的信息设置现在播放的信息中心字典的值。,以一致的方式处理信息的显示。"
我发现,如果我没有设置nowPlayingInfo n mpnowplayinginfocenter,那么我试图摆脱默认锁定屏幕播放器没有注册的更改。确保您正在设置mpnowplayinginfocenter.defaultcenter()。在某些时候如下:
: var songInfo: NSMutableDictionary = [
MPMediaItemPropertyTitle: "song title",
MPMediaItemPropertyArtist: "artiest ",
]
MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = songInfo as [NSObject : AnyObject]