在iTunes中可以使用封面时,MPMediaItemArtwork为空
UIImage
“图片”始终是空的(“空”),虽然封面显示在音乐应用程序由苹果。 在iOS 7中,它工作正常,但与iOS 8我没有掩护。
我的代码有什么问题,或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
的select器imageWithSize:(CGSize)size
似乎不能保证它将返回一个图像。 如果没有图像以请求的尺寸返回,请使用图片bounds
属性的大小重新调用它:
MPMediaItemArtwork *artwork = [self valueForProperty:MPMediaItemPropertyArtwork]; UIImage *image = [artwork imageWithSize:size]; if (image == nil) { image = [artwork imageWithSize:artwork.bounds.size]; }
我发现了这个问题。
它的
CGSize artworkImageViewSize = CGSizeMake(100, 100);
以下作品:
CGSize artworkImageViewSize = CGSizeMake(120, 120);
要么
CGSize artworkImageViewSize = CGSizeMake(60, 60);
一切可以分为3件作品。
你的代码看起来很好。 我有相同的代码获取艺术品,它在iOS 8上为我工作。你是否确定项目实际上有艺术品? 在音乐应用程序中播放该歌曲 – 艺术品?