【问题标题】:Get meta data displayed in MPNowPlayingInfoCenter's nowPlayingInfo(lock screen and remote control)获取 MPNowPlayingInfoCenter 的 nowPlayingInfo 中显示的元数据(锁屏和远程控制)
【发布时间】:2013-12-30 08:36:37
【问题描述】:

感谢您注意到这个问题。我想做一些关于音乐推荐的事情,我现在正在做的是利用MPNowPlayingInfoCenternowPlayingInfo,像这样:

NSDictionary *metaData = [[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo];
NSString *songTitle = metaData[MPMediaItemPropertyTitle];
NSString *albumnTitle = metaData[MPMediaItemPropertyAlbumTitle];
NSString *artist = metaData[MPMediaItemPropertyArtist];

但当“音乐”应用在后台播放音乐时,它总是返回 nil。 我查了相关文件,上面写着

 MPNowPlayingInfoCenter provides an interface for setting the current now 
 playing information for the application.
 The default center holds now playing info about the current application

似乎无法通过MPNowPlayingInfoCenter 获取其他应用的nowPlayingInfo。那么还有其他方法可以让其他应用的音乐元数据显示在遥控器/锁定屏幕中吗?谢谢!

【问题讨论】:

  • 为什么要获取其他应用的数据?
  • @Desmond 因为我想根据用户的兴趣向他/她推荐一些信息。音乐是一个很好的提示。
  • 嗨,我曾尝试获取 nowplayinginfo,但无济于事。我不确定你是否能得到这些信息,因为所有应用程序都是沙盒的。

标签: ios avfoundation mpnowplayinginfocenter


【解决方案1】:

您可以获取 iPod 当前正在播放的内容

MPMusicPlayerController* player = [MPMusicPlayerController iPodMusicPlayer];
//get now playing item
MPMediaItem*item = [player nowPlayingItem];
// get the title of song
NSString* titleStr = [item valueForProperty:MPMediaItemPropertyTitle];
NSLog(@"titlestr %@",titleStr);

【讨论】:

  • [player nowPlayingItem] 为我返回 nil
  • @hodgesmr 您确定正在播放音乐 (iPod) 应用程序,而不是播客之类的其他应用程序吗?
  • 它不适用于 Spotify 等第三方应用,仅适用于 iOS 播放器。
猜你喜欢
  • 2016-03-01
  • 2016-04-17
  • 2016-01-07
  • 1970-01-01
  • 1970-01-01
  • 2015-03-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多