MPNowPlayingInfoCenter是否与AVAudioPlayer兼容?

我开始玩AVAudioPlayer ,然后像这样设置nowPlaying字典:

 NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];       MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imagedNamed:@"AlbumArt"]]; [songInfo setObject:@"Audio Title" forKey:MPMediaItemPropertyTitle]; [songInfo setObject:@"Audio Author" forKey:MPMediaItemPropertyArtist]; [songInfo setObject:@"Audio Album" forKey:MPMediaItemPropertyAlbumTitle]; [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork]; [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo]; 

locking屏幕始终显示一个暂停button。 我正确接收遥控器事件,并且可以通过遥控器事件切换播放/暂停,但即使在播放时,locking屏幕仍然显示“暂停”。

现在我看到了这个与MPMoviePlayerController的工作。 有人可以解释一下MPNowPlayingInfoCenter如何确定它是否应该显示播放或暂停button?

你有没有在AVAudioSessionCategory上设置正确的AudioSession ? 它需要AVAudioSessionCategoryPlayback我相信得到它的工作。

我目前没有使用MPNowPlaying ,但显然我必须为了获取locking屏幕上显示的audio信息。

但是,除了@ user3061915所说的,要pipe理play / pausebutton,我已经使用了UIEventTypeRemoteControl ,它适用于控制play / pausebutton:

 - (void)remoteControlReceivedWithEvent:(UIEvent *)event { //if it is a remote control event handle it correctly if (event.type == UIEventTypeRemoteControl) { if (event.subtype == UIEventSubtypeRemoteControlPlay) { [self playAudio]; } else if (event.subtype == UIEventSubtypeRemoteControlPause) { [self pauseAudio]; } else if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) { [self togglePlayPause]; //This method will handle the toggling. } } 

我只是在我自己的应用程序中修复了这样的问题。 我最初使用[[AVAudioSession sharedInstance] setCategory:withOptions:error:]并提供了AVAudioSessionCategoryOptionMixWithOthers和AVAudioSessionCategoryOptionDuckOthers。 这原来是我的问题。 如果你与他人混合,你不会得到远程控制事件。 他们仍然去iPod应用程序。 如果你设置了鸭子,你会得到远程控制事件,但是看起来好像它会引起你描述的问题:播放/暂停button显示错误的东西。 我不知道为什么。 我得到了播放/暂停button来通过设置选项为0,或实际上只是调用setCategory:error :.