Posted By

funkypanda on 12/19/09


Tagged

info media ipod


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

joshparnham
bobbym245


Retrieve info of the now playing media item in iPod


 / Published in: iPhone
 

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

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

Report this snippet  

You need to login to post a comment.