首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MPRemoteCommandCenter禁用了所有控件

MPRemoteCommandCenter禁用了所有控件
EN

Stack Overflow用户
提问于 2019-05-03 16:37:31
回答 1查看 1K关注 0票数 0

你好,亲爱的同事们,我需要你们的帮助。当我添加MPChangePlaybackPositionCommand时,我的所有控件(播放/暂停/Rew/锁定屏幕上的下一个轨道)都被自动禁用。滑块的播放在锁定屏幕上工作完美,但我不能按没有人控制按钮,为什么-我不知道。

我也试过这个:

代码语言:javascript
复制
[[MPRemoteCommandCenter sharedCommandCenter].playCommand setEnabled:YES];
[[MPRemoteCommandCenter sharedCommandCenter].pauseCommand setEnabled:YES];
[[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand setEnabled:YES];
[[MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand setEnabled:YES]; 

我的代码非常简单:

代码语言:javascript
复制
 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];

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-03 17:07:16

让我们以播放/暂停按钮为例。这是不够的,使它。您还必须实现它(对于用Swift编写文章表示歉意;我太懒了,无法将其转换回Objective,但您肯定明白其中的意义):

代码语言:javascript
复制
let mprc = MPRemoteCommandCenter.shared()
mprc.playCommand.addTarget(self, action:#selector(doPlay))
mprc.pauseCommand.addTarget(self, action:#selector(doPause))

等等,以及实际的doPlaydoPause实现。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55973976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档