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
Game Engine Collison Bitmask... Why 0X01 etc
Swift Unsafemutablepointer<Unmanaged<Cfstring>> Allocation and Print
How to Check Text Field Input at Real Time
Change Pin Image on Mkmapview in Swift
Nspredicate Filtered by Year Moth Day
Xcode5 Simulator: Unknown Option Character 'X' In: -Xlinker
iOS Uiwebview Crash in "Webthread"
Uipageviewcontroller Gesture Is Calling Viewcontrollerafter: But Doesn't Animate
How to Show Specific Language Keyboard When User Input Values in Uitextfield in iPhone App
iOS Calculate Text Height in Tableview Cell
Canopenurl Not Working in iOS 10
Avplayer Uitapgesturerecognizer Not Working
iOS - Custom Table Cell Not Full Width of Uitableview
Is There a Custom Url Scheme for the Built-In Contacts App
How to Solve This Exc_Bad_Access(Code=Exc_I386_Gpflt )In Swift Programming