For some reason I cannot get an image album into my UIImageView. It is added in storyboard and declared:
@property (strong, nonatomic) IBOutlet UIImageView *displayAlbum;
@synthesize displayAlbum, titleLbl, artist;
In my code:
displayAlbum = [[UIImageView alloc] init];
MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:@"1079287588763212246" forProperty:MPMediaEntityPropertyPersistentID];
MPMediaQuery *query = [[MPMediaQuery alloc] init];
[query addFilterPredicate: predicate];
NSArray *queryResults = [query items];
for (MPMediaItem *song in queryResults) {
MPMediaItemArtwork *artwork = [song valueForProperty: MPMediaItemPropertyArtwork];
[displayAlbum setImage: [artwork imageWithSize:CGSizeMake(displayAlbum.frame.size.width, displayAlbum.frame.size.height)]];
}
I am able to get other song information so its definitely getting the right song, but the ImageView
always shows up blank.
On a side note, if anybody could help me clean up the above bit of code, especially get rid of the for
loop (it should always only return one result anyways) that would be great. Thanks
It's because you're creating a new image view with alloc init, instead of using the one you created in IB. You should just delete that alloc init line.