【问题标题】:MPRemoteCommandCenter disabled all controlsMPRemoteCommandCenter 禁用了所有控件
【发布时间】:2019-05-03 16:37:31
【问题描述】:

亲爱的同事,您好,我需要您的帮助。当我添加 MPChangePlaybackPositionCommand 时,我的所有控件(锁屏上的播放/暂停/重播/下一曲目)都已自动禁用。锁屏上播放的滑块完美运行,但我无法按下任何控制按钮 - 我不知道。

我也试过这个:

[[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];

【问题讨论】:

  • @matt 不一样,因为我的滑块工作得很好。我也使用 - - (void)remoteControlReceivedWithEvent:(UIEvent *)theEvent 但没有一个积极的结果...=\
  • 而且我的信息中心工作正常,因为我在锁屏上有名字歌曲
  • 您说您的滑块运行良好,但显然情况并非如此,因为它禁用了界面的其余部分。我不是专家,但在我看来,关于更新指挥中心有关播放速率和播放位置的信息的建议在这里可能非常密切。
  • @matt 我的滑块可以完美运行,因为我可以更改播放器的播放速率。调用 MPRemoteCommandCenter 时,所有控件都已禁用...

标签: ios xcode avplayer mpremotecommandcenter


【解决方案1】:

我们以播放/暂停按钮为例。 启用它是不够的。你还必须实现它(我很抱歉用 Swift 编写;我懒得翻译回 Objective-C,但你肯定能明白这一点):

let mprc = MPRemoteCommandCenter.shared()
mprc.playCommand.addTarget(self, action:#selector(doPlay))
mprc.pauseCommand.addTarget(self, action:#selector(doPause))

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

【讨论】:

  • MPRemoteCommand *playCommand = [[MPRemoteCommandCenter sharedCommandCenter]playCommand]; [playCommand addTarget:self action:@selector(playSelector:)]; [[MPRemoteCommandCenter sharedCommandCenter].playCommand setEnabled:YES];
  • 这也不是一个结果..确切地说,当我按下我的界面播放器时 - 暂停,按钮暂停/播放 - 激活!但是当播放器开始播放时 - 锁屏按钮再次被禁用...
  • [[MPRemoteCommandCenter sharedCommandCenter].playCommand addTarget:self action:@selector(playCommand)];这是解决我的问题!谢谢@matt
  • 你是对的。我执行播放和停止命令,它显示禁用按钮。我听从你的建议,当我实现暂停功能时,它会显示启用按钮。
猜你喜欢
  • 2016-12-23
  • 2023-03-21
  • 1970-01-01
  • 2011-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多