我有以下代码从 MPMediaItemPropertyArtWork 获取 UIImage 以在我的 View 中显示coverArt。我从 mediaItem 获得了一个非 NULL 图稿,但是,当我尝试从图稿中提取 UIImage 时,它​​返回 NULL 并且我在 UIImageView 中看不到任何内容。任何帮助将不胜感激。

CGSize artworkSize = CGSizeMake(30, 30);
UIImage *artworkImage;
MPMediaItemArtwork *artwork = [song valueForProperty: MPMediaItemPropertyArtwork];
if (artwork) {
    NSLog(@"artwork available");
    artworkImage = [artwork imageWithSize:artworkSize];
} else {
    NSLog(@"artwork not available");
    artworkImage = [UIImage imageNamed:@"EmptyAlbum.png"];
}

NSLog(@"artworkImage = %@", artworkImage);

coverArtView.image = artworkImage;

最佳答案

试试这个 - 使用 UItableview 来显示专辑详细信息。

声明 MPMediaItemCollection *userMediaCollection;

 -(void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {

[self setUserMediaCollection:mediaItemCollection];

[self dismissModalViewControllerAnimated:YES];

  }


MPMediaItem *mItem = (MPMediaItem *)[userMediaCollection.items  objectAtIndex:indexPath.row];

    MPMediaItemArtwork *artWork = [mItem valueForProperty:MPMediaItemPropertyArtwork];

    cell.imageView.image = [artWork imageWithSize:CGSizeMake(30, 30)];

其中 userMediaCollection 是您的 MPMediaItemCollection

关于iphone - 无法从 MPMediaItemPropertyArtWork 获取 UIImage,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6604829/

10-12 00:19
查看更多