【发布时间】:2015-05-30 01:17:15
【问题描述】:
我一直在编写使用[MPMusicPlayerController applicationMusicPlayer] 播放音乐的代码。
这已成功运行,并将在控制中心屏幕上显示当前播放曲目的详细信息。
很遗憾,我似乎无法从控制中心屏幕或耳机上操作遥控器按钮。
我已启用为应用程序制作的背景音频将在后台播放,并已使用类似于下面显示的代码启用了一些 MPRemoteCommandCenter 命令。下面的代码是基于我在文档和SO question
中看到的MPRemoteCommandCenter *rcc = [MPRemoteCommandCenter sharedCommandCenter];
MPRemoteCommand *playCommand = rcc.playCommand;
playCommand.enabled = YES;
[playCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent *event) {
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
[musicPlayer play];
NSLog(@"Play button pressed");
return MPRemoteCommandHandlerStatusSuccess;
}];
使用上面的代码,它会导致控制中心按钮不执行任何操作或开始播放音乐应用程序。
我确定我缺少一些简单但似乎看不到的东西。我试过打电话给[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];,但据我所知,这不应该与 MPRemoteCommandCenter 一起使用。
我正在使用 Xcode 6.2 和 iOS 8.2。
我已经在这里尝试了所有我能想到的方法......如何让 MPRemoteCommandCenter 按我的预期工作?
【问题讨论】:
-
查看这个对另一个问题的详细回复 - stackoverflow.com/a/24818340/558575
-
@amergin,谢谢,但我已经看过那个链接了。我认为我的问题与 [MPMusicPlayerController applicationMusicPlayer] 密切相关。我已经让远程指挥中心工作,但仅适用于 [MPMusicPlayerController systemMusicPlayer]。
-
您好,@MikeMeyers,我也遇到了同样的问题。您能否告诉我您是否设法让 applicationMusicPlayer 接收远程事件?谢谢!
-
@cpprulez,我在这方面没有取得任何进展,自从几个月前我问过这个问题以来,我还没有碰过它。也许我应该在 iOS 9 上尝试一下,或者向 Apple 提出一个错误。
-
我也有同样的问题。我不一定需要对命令做出响应,但它们目前什么都不做!我向 Apple 发起了开发者支持请求。