ArtSabintsev
ArtSabintsev

Reputation: 5180

Getting name of track that is currently being played

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!

Upvotes: 3

Views: 364

Answers (2)

James Boutcher
James Boutcher

Reputation: 2613

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!
}

Upvotes: 0

ArtSabintsev
ArtSabintsev

Reputation: 5180

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.

Upvotes: 4

Related Questions