Retrieve info of the now playing media item in iPod


/ Published in: iPhone
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // instantiate a music player
  2. MPMusicPlayerController *iPodMediaPlayer;
  3. iPodMediaPlayer = [MPMusicPlayerController iPodMusicPlayer];
  4.  
  5. // Check if it is now playing
  6. if([iPodMediaPlayer nowPlayingItem]){
  7. NSLog(@"iPod is playing");
  8.  
  9. // Get the now playing item
  10. MPMediaItem *nowPlayingMediaItem = [iPodMediaPlayer nowPlayingItem];
  11.  
  12. // Get info of the item
  13. NSString *itemTitle = [nowPlayingMediaItem valueForProperty: MPMediaItemPropertyTitle];
  14. NSString *itemArtist = [nowPlayingMediaItem valueForProperty: MPMediaItemPropertyArtist];
  15.  
  16. NSLog([[NSString alloc] initWithFormat:@"playing: %@ by %@", itemTitle, itemArtist]);
  17.  
  18.  
  19. } else {
  20. NSLog(@"iPod is not plaing");
  21. }

URL: http://developer.apple.com/iphone/library/documentation/Audio/Conceptual/iPodLibraryAccess_Guide/UsingMediaPlayback/UsingMediaPlayback.html#//apple_ref/doc/uid/TP40008765-CH100-SW1

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.