获取显示在MPNowPlayingInfoCenter的nowPlayingInfo中的元数据(锁定屏幕和遥控器) [英] Get meta data displayed in MPNowPlayingInfoCenter's nowPlayingInfo(lock screen and remote control)

查看:365
本文介绍了获取显示在MPNowPlayingInfoCenter的nowPlayingInfo中的元数据(锁定屏幕和遥控器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Thanks for noticing this question. I want to do something about music recommendation, and what I am doing now is leveraging MPNowPlayingInfoCenter's nowPlayingInfo, like this:

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

但是,当音乐"应用在后台播放音乐时,它始终返回nil. 我查了相关文件,上面写着

But it always returns nil when "Music" app is playing music in background. I looked up the related documents, it says

 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.那么,还有其他方法可以让其他应用的音乐元数据显示在远程控制/锁定屏幕上吗?谢谢!

Seems there is no way to get other app's nowPlayingInfo through MPNowPlayingInfoCenter. So are there any other ways to get other app's music meta data displayed in remote control/lock screen? Thanks!

推荐答案

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

You can get what iPod currently is playing

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

这篇关于获取显示在MPNowPlayingInfoCenter的nowPlayingInfo中的元数据(锁定屏幕和遥控器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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