【问题标题】:MPRemoteCommandCenter pause/play button not toggling?MPRemoteCommandCenter 暂停/播放按钮不切换?
【发布时间】:2015-07-16 20:29:00
【问题描述】:

我在 MPRemoteCommandCenter 中切换播放和暂停按钮时遇到问题。无论出于何种原因,音频和事件都将正常工作,但命令中心不会将播放按钮更改为暂停按钮。这是我的代码...

- (void)setupMPRemoteCommandCenter{
    MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];

    MPRemoteCommand *play = [commandCenter playCommand];
    [play setEnabled:YES];
    [play addTarget:self action:@selector(playAudio:)];

    MPRemoteCommand *pause = [commandCenter pauseCommand];
    [pause setEnabled:YES];
    [pause addTarget:self action:@selector(playAudio:)];


    [commandCenter.skipBackwardCommand setPreferredIntervals:@[@30.0]];
    MPRemoteCommand *skipBackwards = [commandCenter skipBackwardCommand];
    [skipBackwards setEnabled:YES];
    [skipBackwards addTarget:self action:@selector(skipBackwardEvent:)];

    [commandCenter.skipForwardCommand setPreferredIntervals:@[@30.0]];
    MPRemoteCommand *skipForwards = [commandCenter skipForwardCommand];
    [skipForwards setEnabled:YES];
    [skipForwards addTarget:self action:@selector(skipForwardEvent:)];

}
-(void)playAudio: (MPRemoteCommandHandlerStatus *)event{
    [self playAction];
    //playAction handles the audio pausing and toggling the play button on the app
}

如果你们能想到什么,请告诉我,我很乐意提供帮助。这让我发疯了

【问题讨论】:

  • 不幸的是,你在同一个地方。你解决过你的问题吗?
  • 我面临同样的问题。任何帮助将不胜感激!
  • 我最终放弃了这个项目,抱歉回复晚了!希望你能弄清楚
  • 我也面临同样的问题..你找到解决方案了吗@ColinFausnaught
  • @IosDeveloper 我最终离开了 iOS 开发,自从这篇文章之后就没有从事过这个项目,抱歉!

标签: ios objective-c media-player


【解决方案1】:

关于我如何解决这个问题的一些指示。 阅读苹果documentation 它声明“您的应用必须是“正在播放”应用。应用在开始播放音频之前不会接收远程控制事件”

所以首先开始播放音频。

MPRemoteCommandCenter 是一个相当独立的模块。 setEnabled 用于明确表示不支持某些内容。不要在活动期间将其用作切换,AVFoundation 将自行处理。

另外请注意,我在模拟器中切换时遇到问题,它在设备上切换正常,但在模拟器中却没有,这花了 16 个小时才弄清楚:)

【讨论】:

  • 不知道为什么这会被否决。模拟器对 MPRemoteCommandCenter 反应不佳的事实对我帮助很大!
  • 那些错误总是找我。有些东西在模拟器上不工作,我很沮丧,只是意识到一切都在设备上工作。
猜你喜欢
  • 2016-08-13
  • 2019-06-25
  • 2016-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-31
  • 1970-01-01
相关资源
最近更新 更多