MPMediaItemArtwork is null while cover is available in iTunes

前端 未结 3 1536
慢半拍i
慢半拍i 2020-12-18 04:00

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.

相关标签:
3条回答
  • 2020-12-18 04:34

    i´ve found the problem.

    it´s

     CGSize artworkImageViewSize = CGSizeMake(100, 100);
    

    the following works:

     CGSize artworkImageViewSize = CGSizeMake(120, 120);
    

    or

     CGSize artworkImageViewSize = CGSizeMake(60, 60);
    

    everything that can be divided by 3 works.

    0 讨论(0)
  • 2020-12-18 04:45

    Your code looks fine. I have the same code for getting artwork and it's working for me on iOS 8. Are you SURE the item actually has artwork? Play that song in the music app - artwork?

    0 讨论(0)
  • 2020-12-18 04:54

    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];
    }
    
    0 讨论(0)
提交回复
热议问题