MPMediaItem *song; MPMediaPropertyPredicate *predicate; MPMediaQuery *songQuery; predicate = [MPMediaPropertyPredicate predicateWithValue: MyPersistentIdString forProperty:MPMediaItemPropertyPersistentID]; songQuery = [[MPMediaQuery alloc] init]; [songQuery addFilterPredicate: predicate]; if (songQuery.items.count > 0) { //song exists song = [songQuery.items objectAtIndex:0]; CellDetailLabel = [CellDetailLabel stringByAppendingString:[song valueForProperty: MPMediaItemPropertyTitle]]; }
Category: Songs and Playlists
Read all songs
Add the MediaPlayer.Framework to your project #import <MediaPlayer/MPMediaQuery.h> #import <MediaPlayer/MPMediaPlaylist.h> //—– LIST ALL SONGS —– MPMediaQuery *everything = [[MPMediaQuery alloc] init]; NSLog(@”Logging items from a generic query…”); NSArray *itemsFromGenericQuery = [everything items]; for (MPMediaItem *song in itemsFromGenericQuery) { NSString *songTitle = [song valueForProperty: MPMediaItemPropertyTitle]; NSLog (@”%@”, songTitle); NSLog (@”\t%@”, [song valueForProperty: MPMediaItemPropertyPersistentID]); }
Read iTunes Playlists
Add the MediaPlayer.Framework to your project #import <MediaPlayer/MPMediaQuery.h> #import <MediaPlayer/MPMediaPlaylist.h> //—– LIST ALL PLAYLISTS —– MPMediaQuery *myPlaylistsQuery = [MPMediaQuery playlistsQuery]; NSArray *playlists = [myPlaylistsQuery collections]; for (MPMediaPlaylist *playlist in playlists) { NSLog (@”%@”, ); NSLog (@”%@”, ); NSArray *songs = ; for (MPMediaItem *song in songs) { NSString *songTitle = [song valueForProperty: MPMediaItemPropertyTitle]; NSLog (@”\t\t%@”, […]