本文介绍了如何使“控制中心"滑块可编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个将播放声音文件的应用程序.如果我打开苹果音乐应用程序,则滑块可让我在我所在的歌曲之间移动.

I'm working on an app that will play sound files. If I open apple music app, the slider let me moving between the song where I am.

spotify或overcast等其他应用不允许这种行为.

Other apps like spotify or overcast does not allow this behaviour.

直到现在,我已经能够更改控制中心的所有参数,但有例外.有什么方法可以使此滑块有用吗?

Until now, I have been able to change all parameters of the control center with that exception. Is there any way of making this slider useful?

我使用的是以下代码:

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 )

There is the changePlaybackPositionCommand API with the associated Event MPChangePlaybackPositionCommandEvent.positionTime (see 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;
}

,但是光标仍然不能移动,并且不会调用该方法.我想我还是想念东西

but the cursor is still not movable and the method is not called. I guess I still miss something

这篇关于如何使“控制中心"滑块可编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 14:57