Question

I'm using the media player framework to get the artwork of the song that's currently playing, but every time a song is played that has no album artwork, the UIImageView I load the artwork into is empty. Is there a way to have a placeholder image that is displayed every time a song with no artwork is played?

Was it helpful?

Solution

This is how I use a placeholder for songs that do not have artwork:

artworkImageView = [[UIImageView alloc] initWithFrame:CGRectMake(x,y,160,160)];

CGSize artworkImageViewSize = artworkImageView.bounds.size;
artwork = [currentItem valueForProperty:MPMediaItemPropertyArtwork];
if (artwork != nil) {
    artworkImageView.image = [artwork imageWithSize:artworkImageViewSize];
}else{
    artworkImageView.image = [UIImage imageNamed:@"NoAlbumArt.png"];
}

OTHER TIPS

I ran into the same issue... basically it works perfectly on the simulator but not on an actual device... instead I did the following:

artworkImageView = [[UIImageView alloc] initWithFrame:CGRectMake(x,y,160,160)];
CGSize artworkImageViewSize = artworkImageView.bounds.size;
artwork = [currentItem valueForProperty:MPMediaItemPropertyArtwork];
if (artwork != nil) {
     artworkImageView.image = [artwork imageWithSize:artworkImageViewSize];
     if(artworkImageView.image == NULL){
          artworkImageView.image = [UIImage imageNamed:@"NoAlbumArt.png"];
     }
}

and that seemed to fix the issue so it works on both the simulator and actual device

Before making changes, please make sure that UIImageView is set to "Aspect Fit" which worked for me. It didn't work when I had "Scale to fill".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top