3

Is there a way to get the name of the track that is currently being played in iTunes on an iOS device?

I haven't found anything too useful inMPMusicPlayerController nor AVAudioPlayer.

Thanks!

ArtSabintsev
  • 5,170
  • 10
  • 41
  • 71

2 Answers2

4

Alright, after some more searching, I found the answer hidden in this semi-related question: Get album artwork from MP3 file/ID3 tag

There are two properties that exist in MPMusicPlayerController that provides us with the Track Name and Track Artist. They are MPMediaItemPropertyTitle and MPMediaItemPropertyArtist, respectively.

Community
  • 1
  • 1
ArtSabintsev
  • 5,170
  • 10
  • 41
  • 71
  • Have to wait for 22 more hours - found the answer couple hours after posting the question. Glad to hear it works! =p – ArtSabintsev Oct 29 '11 at 22:34
0

The accepted answer's answer contains 5x the code you need to get what you're after. Here's a simpler answer:

if ([MPMusicPlayerController iPodMusicPlayer].playbackState == MPMusicPlaybackStatePlaying) {
    MPMediaItem *item = [[MPMusicPlayerController iPodMusicPlayer] nowPlayingItem];
    NSString *title = [item valueForProperty:MPMediaItemPropertyTitle];
    NSString *artist = [item valueForProperty:MPMediaItemPropertyArtist]; // common
    // do something with these
} else {
    // nothing is playing!
}
James Boutcher
  • 2,593
  • 1
  • 25
  • 37