3

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

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

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

4

1 回答 1

3

您可以获取 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);
于 2014-01-20T05:05:57.433 回答