문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top