我正在更新MPNowPlayingInfoCenter,但遇到了一些麻烦。我试了相当多,到了不知所措的地步。以下是我的代码:
self.audioPlayer.allowsAirPlay = NO;
Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if (playingInfoCenter) {
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"series_placeholder"]];
[songInfo setObject:thePodcast.title forKey:MPMediaItemPropertyTitle];
[songInfo setObject:thePodcast.author forKey:MPMediaItemPropertyArtist];
[songInfo setObject:@"NCC" forKey:MPMediaItemPropertyAlbumTitle];
[songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
}这不管用,我也试过了:
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nil];试图让它从iPod应用程序(或任何可能有信息的应用程序)中删除现有信息。此外,为了看看我是否能找出问题所在,我尝试在应用程序启动时检索当前信息:
NSDictionary *info = [[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo];
NSString *title = [info valueForKey:MPMediaItemPropertyTitle];
NSString *author = [info valueForKey:MPMediaItemPropertyArtist];
NSLog(@"Currently playing: %@ // %@", title, author);我得到了Currently playing: (null) // (null)
我已经对此进行了相当多的研究,下面的文章对它进行了相当彻底的解释,然而,我仍然无法让它正常工作。我是不是遗漏了什么?会有什么干扰吗?这是我的应用程序需要注册才能访问的服务吗(在任何文档中都没有看到)?
发布于 2012-03-03 00:47:47
我终于找到了问题所在,我没有提示我的应用程序接收远程控制事件,只需添加下面这行就解决了这个问题:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];发布于 2012-03-02 03:59:04
我使用下面的代码,它总是有效的。我也像你一样使用MPMoviePlayer。你检查过NSClassFromString(@"MPNowPlayingInfoCenter")是否真的返回过YES吗?你有没有设置你的应用程序播放音频在背景键你的plist?
- (void) loadMPInformation
{
NSDictionary *mpInfo;
if([savedTrack.belongingAlbum.hasAlbumArt boolValue] == NO){
mpInfo = [NSDictionary dictionaryWithObjectsAndKeys:savedTrack.belongingAlbum.album, MPMediaItemPropertyAlbumTitle,
savedTrack.belongingArtist.artist, MPMediaItemPropertyArtist, savedTrack.name, MPMediaItemPropertyTitle, nil];
} else {
UIImage *artImage = [UIImage imageWithData:savedTrack.belongingAlbum.art];
MPMediaItemArtwork *artwork = [[MPMediaItemArtwork alloc] initWithImage:artImage];
mpInfo = [NSDictionary dictionaryWithObjectsAndKeys:savedTrack.belongingAlbum.album, MPMediaItemPropertyAlbumTitle,
savedTrack.belongingArtist.artist, MPMediaItemPropertyArtist, savedTrack.name, MPMediaItemPropertyTitle, artwork, MPMediaItemPropertyArtwork, nil];
}
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = mpInfo;
}https://stackoverflow.com/questions/9522591
复制相似问题