MPMediaItemArtwork 为空,而封面在 iTunes 中可用 [英] MPMediaItemArtwork is null while cover is available in iTunes
本文介绍了MPMediaItemArtwork 为空,而封面在 iTunes 中可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
UIImage
图像"始终为空(null"),尽管 Apple 的音乐应用程序中显示了封面.在 iOS 7 中它工作正常,但在 iOS 8 中我没有任何掩护.
The UIImage
"image" is always empty ("null") though the cover is shown in the music app by apple.
in iOS 7 it works fine, but with iOS 8 I get no cover.
我的代码有什么问题,或者 iOS 8 有什么变化?
Whats wrong with my code, or what has changed in iOS 8?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
AlbumCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AlbumCell"];
MPMediaItemCollection *song = self.songsList[indexPath.row];
cell.albumName.text = [[song representativeItem] valueForProperty: MPMediaItemPropertyAlbumTitle];
cell.albumArtist.text = [[song representativeItem] valueForProperty:MPMediaItemPropertyAlbumArtist];
CGSize artworkImageViewSize = CGSizeMake(100, 100);
MPMediaItemArtwork *artwork = [song valueForProperty:MPMediaItemPropertyArtwork];
UIImage *image = [artwork imageWithSize:artworkImageViewSize];
NSLog(@"-------------------");
NSLog(@"%@",[[song representativeItem] valueForProperty: MPMediaItemPropertyAlbumTitle]);
NSLog(@"%@",image);
if (artwork) {
cell.cover.image = image;
}
else
{
cell.cover.image = [UIImage imageNamed:@"nocover.png"];
}
return cell;
}
推荐答案
从 iOS 8 开始,MPMediaItem
的选择器 imageWithSize:(CGSize)size
似乎不能保证它将返回一个图像.如果没有以请求的大小返回图像,则使用艺术品的大小再次调用它bounds
属性:
As of iOS 8, MPMediaItem
's selector imageWithSize:(CGSize)size
appears to not guarantee that it will return an image. If no image is returned at the requested size, call it again with the size of the artwork bounds
property:
MPMediaItemArtwork *artwork = [self valueForProperty:MPMediaItemPropertyArtwork];
UIImage *image = [artwork imageWithSize:size];
if (image == nil) {
image = [artwork imageWithSize:artwork.bounds.size];
}
这篇关于MPMediaItemArtwork 为空,而封面在 iTunes 中可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文