Access current track information from iTunes to iPod

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

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

+3
source share
1 answer

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

then

sort of

@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 current item is changed, you will receive a notification by calling this method

- (void)handleNowPlayingItemChanged:(id)notification {
    // Ask the music player for the current song.
    MPMediaItem *currentItem = self.musicPlayer.nowPlayingItem;
+6
source

Source: https://habr.com/ru/post/1741064/


All Articles