首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MPMusicPlayerController不会与远程控件交互

MPMusicPlayerController不会与远程控件交互
EN

Stack Overflow用户
提问于 2016-08-12 13:00:12
回答 1查看 1K关注 0票数 4

尽管这个问题问了很多次,但我没有找到满意的答案,但我还是想再试一次:

我想和MPMediaItems一起玩MPMusicPlayerController。到目前一切尚好。这是需要播放来自Itunes或Apple的文件。任何其他文件都是通过AVPlayer播放的。

使用以下方法处理使用AVPlayer播放的歌曲的远程控件似乎没有问题:

代码语言:javascript
复制
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];

代码语言:javascript
复制
- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent

此外,还可以在背景中检索AVPlayerItemDidPlayToEndTimeNotification,对此作出反应,开始播放下一首歌曲。

尝试所有这些与MPMusicPlayerController一起播放一首歌似乎不像它应该做的那样有效。我试着唱一首这样的歌:

代码语言:javascript
复制
 self.audioPlayer = [MPMusicPlayerController applicationMusicPlayer];
 self.audioPlayer.repeatMode = MPMusicRepeatModeNone;
 [self.audioPlayer setQueueWithItemCollection:[MPMediaItemCollection collectionWithItems:@[_playerItem]]];

利用给定的观察员:

代码语言:javascript
复制
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(playbackStateDidChange:) name:MPMusicPlayerControllerPlaybackStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(playbackItemDidChange:) name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification object:nil];
[self.audioPlayer beginGeneratingPlaybackNotifications];

如果应用程序在前台,观察员就会被按他们应有的方式调用。作为背景,观察员不再被调用。在这种情况下,我不可能检测到歌曲的结尾跳到下一首歌。

同时,遥控器也不能工作。我用:

代码语言:javascript
复制
[MPRemoteCommandCenter sharedCommandCenter].playCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].playCommand addTarget:self action:@selector(remotePlay)];

[MPRemoteCommandCenter sharedCommandCenter].pauseCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].pauseCommand addTarget:self action:@selector(remoteStop)];

[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand addTarget:self action:@selector(loadPreviousSong)];

[MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand addTarget:self action:@selector(loadNextSong)];

但是在前景和背景下,这些给定的选择器被称为。

有人能解决我的问题吗?如前所述,我需要使用MPMusicPlayerController,因为我想播放苹果音乐和iTunes匹配音轨。

相关问题:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-22 22:43:31

因为音乐应用程序正在处理项目的实际回放,所以您自己的应用程序没有收到通知。最好的方法是通过bugreport.apple.com提交一个增强请求。

Apple / iTunes团队正在听取关于如何从我在WWDC上得知的改进Apple的反馈意见。

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

https://stackoverflow.com/questions/38918616

复制
相关文章

相似问题

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