0

如果专辑封面不存在,我正在尝试放置一个占位符图像。由于某种原因,representativeItem 中的图像永远不会为空,因此它只是分配了一个空白艺术品......

MPMediaItemArtwork *artwork = [[mediaListItem representativeItem] valueForProperty:MPMediaItemPropertyArtwork];

    if (artwork) {
         sModel.albumImage = [artwork imageWithSize: CGSizeMake (10, 10)];
    } else {
        sModel.albumImage = [UIImage imageNamed:@"Default_.png"]; //never enters
    }
4

1 回答 1

0

找到解决方案,我是天才;)

MPMediaItemArtwork *artwork = [[mediaListItem representativeItem] valueForProperty:MPMediaItemPropertyArtwork];

//If artwork has no size set place holder
if (CGSizeEqualToSize(artwork.bounds.size, CGSizeZero))
{
   sModel.albumImage = [UIImage imageNamed:DEFAULT_IMG];
}
else //Otherwise set the artwork found in the library. 
{
   sModel.albumImage = [artwork imageWithSize: CGSizeMake (SIZE_X, SIZE_Y)];
}
于 2013-01-14T22:47:10.720 回答