【发布时间】:2026-01-04 18:20:03
【问题描述】:
我正在努力更新 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)
我对此进行了相当多的研究,以下文章对此进行了非常彻底的解释,但是,我仍然无法使其正常工作。我错过了什么吗?会有什么干扰吗?这是我的应用需要注册才能访问的服务吗(在任何文档中都没有看到)?
【问题讨论】:
-
这段代码执行时是否在播放媒体?
-
我尝试过播放音频(通过 MPMoviePlayer),但结果相同
-
使用 nslog 打印 [MPNowPlayingInfoCenter defaultCenter]。他们在文档中说:默认的正在播放信息中心保存被指定为远程控制事件接收器的应用程序的正在播放信息。您是否在某个远程设备上播放媒体?确保媒体正在某个远程设备上播放。因为文档说:远程控制事件让用户可以通过系统传输控件或外部附件来控制应用程序多媒体。
-
当我打印 MPNowPlayingInfoCenter 我得到:
-
我没有在远程设备或配件上播放...我的理解是您可以通过在设备上播放音频来更新此信息(如锁定屏幕上显示的那样),但它可以也可用于远程设备...
标签: iphone ios mpmovieplayercontroller