如果专辑封面不存在,我正在尝试放置占位符图像。出于某种原因,来自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
}
答案 0 :(得分: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)];
}