感谢您注意到这个问题。我想做一些关于音乐推荐的事情,我现在做的就是利用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
。那么还有其他方法可以让其他应用程序的音乐元数据显示在远程控制/锁定屏幕中吗?谢谢!
您可以获取 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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)