我正在开发一个将播放声音文件的应用程序。如果我打开苹果音乐应用程序,则滑块可让我在我所在的歌曲之间移动。
其他应用程序(例如spotify或overcast)不允许这种行为。
到现在为止,除了那个例外,我已经能够更改控制中心的所有参数。有什么方法可以使此滑块有用吗?
我正在使用类似以下代码的内容:
MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
NSArray *commands = @[commandCenter.playCommand, commandCenter.pauseCommand, commandCenter.nextTrackCommand, commandCenter.previousTrackCommand, commandCenter.bookmarkCommand, commandCenter.changePlaybackPositionCommand, commandCenter.changePlaybackRateCommand, commandCenter.dislikeCommand, commandCenter.enableLanguageOptionCommand, commandCenter.likeCommand, commandCenter.ratingCommand, commandCenter.seekBackwardCommand, commandCenter.seekForwardCommand, commandCenter.skipBackwardCommand, commandCenter.skipForwardCommand, commandCenter.stopCommand, commandCenter.togglePlayPauseCommand];
for (MPRemoteCommand *command in commands) {
[command removeTarget:nil];
[command setEnabled:NO];
}
[commandCenter.playCommand addTarget:self action:@selector(playTrack)];
[commandCenter.pauseCommand addTarget:self action:@selector(pauseTrack)];
[commandCenter.playCommand setEnabled:YES];
[commandCenter.pauseCommand setEnabled:YES];
有changePlaybackPositionCommand API和关联的事件MPChangePlaybackPositionCommandEvent.positionTime(请参阅https://developer.apple.com/library/ios/releasenotes/General/iOS91APIDiffs/Objective-C/MediaPlayer.html)
我试过了
[commandCenter.changePlaybackPositionCommand
addTarget: self
action: @selector( onChangePlaybackPositionCommand: )]
与相关方法
- (MPRemoteCommandHandlerStatus) onChangePlaybackPositionCommand:
(MPChangePlaybackPositionCommandEvent *) event
{
NSLog(@"changePlaybackPosition to %f", event.positionTime);
return MPRemoteCommandHandlerStatusSuccess;
}
但是光标仍然不能移动,并且不会调用该方法。我想我还是想念什么
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句