MPRemoteCommandCenter 禁用所有控件
MPRemoteCommandCenter disabled all controls
尊敬的同事您好,我需要您的帮助。当我添加 MPChangePlaybackPositionCommand 时,我的所有控件(Play/Pause/Rew/Next 锁屏上的轨道)已自动禁用。锁屏上的播放滑块工作得很好,但我无法按下任何一个控制按钮,这是为什么 - 我不知道。
我也试过这个:
[[MPRemoteCommandCenter sharedCommandCenter].playCommand setEnabled:YES];
[[MPRemoteCommandCenter sharedCommandCenter].pauseCommand setEnabled:YES];
[[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand setEnabled:YES];
[[MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand setEnabled:YES];
我的代码很简单:
MPChangePlaybackPositionCommand *changePlaybackPositionCommand = [[MPRemoteCommandCenter sharedCommandCenter] changePlaybackPositionCommand];
[changePlaybackPositionCommand addTarget:self action:@selector(onChangePlaybackPositionCommand:)];
- (MPRemoteCommandHandlerStatus) onChangePlaybackPositionCommand:
(MPChangePlaybackPositionCommandEvent *) event
{
[[[PlayerPlistController utilise]miniplayer] seekToTime:CMTimeMakeWithSeconds(event.positionTime, 1)];
NSLog(@"changePlaybackPosition to %f", event.positionTime);
return MPRemoteCommandHandlerStatusSuccess;
}
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
[songInfo setObject:NAME_TITLE forKey:MPMediaItemPropertyTitle];
[songInfo setObject:NAME_TITLE_SLOGON forKey:MPMediaItemPropertyAlbumTitle];
UIImage *image = [UIImage imageNamed:PLACEHOLDER_EMPTY];
MPMediaItemArtwork *imageArt = [[MPMediaItemArtwork alloc] initWithBoundsSize:image.size requestHandler:^UIImage* _Nonnull(CGSize aSize) { return image; }];
[songInfo setObject:imageArt forKey:MPMediaItemPropertyArtwork];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
我们以播放/暂停按钮为例。 启用 是不够的。你也必须实施它(我很抱歉写在Swift;我懒得翻译回Objective-C,但你一定能看到重点) :
let mprc = MPRemoteCommandCenter.shared()
mprc.playCommand.addTarget(self, action:#selector(doPlay))
mprc.pauseCommand.addTarget(self, action:#selector(doPause))
等等,以及实际的 doPlay
和 doPause
实现。
尊敬的同事您好,我需要您的帮助。当我添加 MPChangePlaybackPositionCommand 时,我的所有控件(Play/Pause/Rew/Next 锁屏上的轨道)已自动禁用。锁屏上的播放滑块工作得很好,但我无法按下任何一个控制按钮,这是为什么 - 我不知道。
我也试过这个:
[[MPRemoteCommandCenter sharedCommandCenter].playCommand setEnabled:YES];
[[MPRemoteCommandCenter sharedCommandCenter].pauseCommand setEnabled:YES];
[[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand setEnabled:YES];
[[MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand setEnabled:YES];
我的代码很简单:
MPChangePlaybackPositionCommand *changePlaybackPositionCommand = [[MPRemoteCommandCenter sharedCommandCenter] changePlaybackPositionCommand];
[changePlaybackPositionCommand addTarget:self action:@selector(onChangePlaybackPositionCommand:)];
- (MPRemoteCommandHandlerStatus) onChangePlaybackPositionCommand:
(MPChangePlaybackPositionCommandEvent *) event
{
[[[PlayerPlistController utilise]miniplayer] seekToTime:CMTimeMakeWithSeconds(event.positionTime, 1)];
NSLog(@"changePlaybackPosition to %f", event.positionTime);
return MPRemoteCommandHandlerStatusSuccess;
}
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
[songInfo setObject:NAME_TITLE forKey:MPMediaItemPropertyTitle];
[songInfo setObject:NAME_TITLE_SLOGON forKey:MPMediaItemPropertyAlbumTitle];
UIImage *image = [UIImage imageNamed:PLACEHOLDER_EMPTY];
MPMediaItemArtwork *imageArt = [[MPMediaItemArtwork alloc] initWithBoundsSize:image.size requestHandler:^UIImage* _Nonnull(CGSize aSize) { return image; }];
[songInfo setObject:imageArt forKey:MPMediaItemPropertyArtwork];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
我们以播放/暂停按钮为例。 启用 是不够的。你也必须实施它(我很抱歉写在Swift;我懒得翻译回Objective-C,但你一定能看到重点) :
let mprc = MPRemoteCommandCenter.shared()
mprc.playCommand.addTarget(self, action:#selector(doPlay))
mprc.pauseCommand.addTarget(self, action:#selector(doPause))
等等,以及实际的 doPlay
和 doPause
实现。