Get meta data displayed in MPNowPlayingInfoCenter's nowPlayingInfo(lock screen and remote control)
Asked Answered
D

1

3

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

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

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!

Deepfreeze answered 12/12, 2013 at 4:16 Comment(3)
why you want to get other app's data ?Parfitt
@Parfitt Because I want to recommend user some information based on his/her interest. Music is a good tip.Deepfreeze
hi i had a go to try on getting the the nowplayinginfo but to no avail. i'm not sure if u could get the info as all app are sandboxed.Parfitt
P
3

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);
Parfitt answered 20/1, 2014 at 5:5 Comment(3)
[player nowPlayingItem] is returning nil for meDys
@Dys Are you sure the Music (iPod) app is playing, and not something else like Podcasts?Scope
It won't work with third-party apps like Spotify, only the iOS player.Provenance

© 2022 - 2024 — McMap. All rights reserved.