MPNowPlayingInfoCenter defaultCenter不会更新或检索信息 [英] MPNowPlayingInfoCenter defaultCenter will not update or retrieve information

查看:1040
本文介绍了MPNowPlayingInfoCenter defaultCenter不会更新或检索信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力更新MPNowPlayingInfoCenter并遇到一些麻烦。我已经尝试了很多,以至于我不知所措。以下是我的代码:

I'm working to update the MPNowPlayingInfoCenter and having a bit of trouble. I've tried quite a bit to the point where I'm at a loss. The following is my code:

    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];


    }

这不起作用,我' ve还试过:

This isn't working, I've also tried:

   [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nil];

试图让它从iPod应用程序中移除现有信息(或任何可能有信息的信息)那里)。另外,为了看看我是否能找到问题,我已经尝试检索应用启动时的当前信息:

In an attempt to get it to remove the existing information from the iPod app (or whatever may have info there). In addition, just to see if I could find out the problem, I've tried retrieving the current information on app launch:

  NSDictionary *info = [[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo];
  NSString *title = [info valueForKey:MPMediaItemPropertyTitle];
  NSString *author = [info valueForKey:MPMediaItemPropertyArtist];

  NSLog(@"Currently playing: %@ // %@", title, author);

我得目前正在播放:(null)//(null)

我对此进行了相当多的研究,以下文章对此进行了彻底的解释,但是,我仍然无法正常工作。我错过了什么吗?会有什么干扰吗?这是我的应用程序需要注册访问的服务(在任何文档中都没有看到这个)吗?

I've researched this quite a bit and the following articles explain it pretty thoroughly, however, I am still unable to get this working properly. Am I missing something? Would there be anything interfering with this? Is this a service something my app needs to register to access (didn't see this in any docs)?

Apple的文档

更改锁定屏幕背景音频控件

现在播放信息被忽略

推荐答案

我终于找到了问题,我没有提示我的应用程序接收远程控制事件,只需添加此行修复了问题:

I finally figured out the problem, I was not prompting my app to receive remote control events, simply adding this line fixed the problem:

 [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

这篇关于MPNowPlayingInfoCenter defaultCenter不会更新或检索信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆