Mediaplayer no album artwork placeholder

1k Views Asked by At

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?

3

There are 3 best solutions below

2
On BEST ANSWER

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"];
}
0
On

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".

0
On

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