Reputation: 567
I am trying to determine the title of the song currently being played on an iPhone. I know I can use the following code to find out what is playing if the native Apple app is playing the music but how do I find the title of a song if its being played from Spotify or some other music playing app?
MPMediaItem *nowPlayingItem = [[MPMusicPlayerController iPodMusicPlayer] nowPlayingItem];
NSString *itemTitle = [nowPlayingItem valueForProperty:MPMediaItemPropertyTitle];
Upvotes: 3
Views: 1648
Reputation: 22873
No you can't get title of song if its playing in some other app!
Edit 1 -
You can't do that because Apple has a very strict policy that runs every app in its own little sandbox that cannot access any other applications data.
-- Thanks Emil ...
Upvotes: 4
Reputation: 18122
Assuming the app supports iOS 5's MPNowPlayingInfoCenter
, you could do this:
NSDictionary *info = [[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo];
NSString *title = [info valueForKey:MPMediaItemPropertyTitle];
Upvotes: -1