I'm trying to query my iPhone to find out the play count of songs and all their data.
I am having trouble with formatting the *info NSString so that it puts in the values for songTitle etc. How can I put all of that into a string, put the string into NSArray *star, then output that to a UITextView?
Code:
NSArray *star;
MPMediaQuery *query = [[MPMediaQuery alloc] init];
[query addFilterPredicate: [MPMediaPropertyPredicate
predicateWithValue: @"Vampire Weekend"
forProperty: MPMediaItemPropertyArtist]];
// Sets the grouping type for the media query
[query setGroupingType: MPMediaGroupingAlbum];
NSArray *albums = [query collections];
for (MPMediaItemCollection *album in albums) {
MPMediaItem *representativeItem = [album representativeItem];
NSString *artistName =
[representativeItem valueForProperty: MPMediaItemPropertyArtist];
NSString *albumName =
[representativeItem valueForProperty: MPMediaItemPropertyAlbumTitle];
NSLog (@"%@ by %@", albumName, artistName);
NSArray *songs = [album items];
for (MPMediaItem *song in songs) {
NSString *playCount = [song valueForProperty:MPMediaItemPropertyPlayCount];
NSString *lastPlayed = [song valueForProperty:MPMediaItemPropertyLastPlayedDate];
NSString *songTitle =
[song valueForProperty: MPMediaItemPropertyTitle];
NSString *info = [[NSString alloc] initWithFormat: @"%@ has been played %@ times.\n Last played %@.", songTitle, playCount, lastPlayed];
NSLog(@"\n%@ has been played %@ times.\n Last played %@.", songTitle, playCount, lastPlayed);
}
}
I am having trouble with formatting the *info NSString so that it puts in the values for songTitle etc. How can I put all of that into a string, put the string into NSArray *star, then output that to a UITextView?