Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing current track information from iTunes on iPod

Is there any iTunes API for the iPhone OS which I can use to access some information (current track, etc.) from iTunes?

I looked around, but all I could find was some AppleScript and COM API.

like image 467
Baishampayan Ghose Avatar asked Dec 07 '25 06:12

Baishampayan Ghose


1 Answers

You need to add MediaPlayer.framework to your target in Xcode and #import MediaPlayer/MediaPlayer.h

then

something like

@property (nonatomic, retain) MPMusicPlayerController *musicPlayer;
...
self.musicPlayer = [MPMusicPlayerController iPodMusicPlayer];

then in viewDidLoad you need to register for the event

// Register for music player notifications
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self 
                       selector:@selector(handleNowPlayingItemChanged:)
                           name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification 
                         object:self.musicPlayer];

implement handleNowPlayingItemChanged now

When the now playing item changes you wll be notified by getting called this method

- (void)handleNowPlayingItemChanged:(id)notification {
    // Ask the music player for the current song.
    MPMediaItem *currentItem = self.musicPlayer.nowPlayingItem;
like image 117
Mihir Mehta Avatar answered Dec 08 '25 18:12

Mihir Mehta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!