Mpmediaitemartwork Is Null While Cover Is Available in Itunes

MPMediaItemArtwork is null while cover is available in iTunes

As of iOS 8, MPMediaItem's selector imageWithSize:(CGSize)size appears to not guarantee that it will return an image. If no image is returned at the requested size, call it again with the size of the artwork bounds property:

MPMediaItemArtwork *artwork = [self valueForProperty:MPMediaItemPropertyArtwork];
UIImage *image = [artwork imageWithSize:size];
if (image == nil)
{
image = [artwork imageWithSize:artwork.bounds.size];
}

iOS - MPMediaItem Display a Default Artwork

MPMediaItemArtwork seem to always exist, even for tracks that don't have artwork.

The way I detect if there's no image is to see if MPMediaItemArtwork's imageWithSize returns NULL.

Or, rejiggering your code a bit:

_item = [_player nowPlayingItem];
UIImage *albumArtworkImage = NULL;
MPMediaItemArtwork *itemArtwork = [_item valueForProperty:MPMediaItemPropertyArtwork];

if (itemArtwork != nil) {
albumArtworkImage = [itemArtwork imageWithSize:CGSizeMake(250.0, 250.0)];
}

if (albumArtworkImage) {
_albumArtImageView.image = albumArtworkImage;
} else { // no album artwork
NSLog(@"No ALBUM ARTWORK");
_albumArtImageView.image = [UIImage imageNamed:@"kol.jpg"];
}

I hope this info helps you out (and if so, mark this answer as checked :-)



Related Topics



Leave a reply



Submit