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!

Hang
  • 469
  • 1
  • 4
  • 18
  • why you want to get other app's data ? – Desmond Jan 12 '14 at 04:54
  • @Desmond Because I want to recommend user some information based on his/her interest. Music is a good tip. – Hang Jan 14 '14 at 09:35
  • 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. – Desmond Jan 19 '14 at 23:53

1 Answers1

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);
Desmond
  • 5,001
  • 14
  • 56
  • 115