MPMediaItem returns blank / transparent music cover

I am having trouble displaying the artwork of the MPMediaItem element.

Here is the code for customizing the cover image:

- (void)updateMusicInfo
{
    if(_localSongList.count != 0)
    {
        _currentTrackNumber = [DataHolder getCurrentTrackNumber];

        MPMediaItem *mediaItem = [_localSongList objectAtIndex:_currentTrackNumber];

        if(mediaItem != nil)
        {
            MPMediaItemArtwork *itemArtwork = [mediaItem valueForKey:MPMediaItemPropertyArtwork];

            UIImage *iconImage;

            if(itemArtwork == nil)
            {
                iconImage = [UIImage imageNamed:@"default_music_cover.png"];
            }

            else
            {
                iconImage = [itemArtwork imageWithSize:CGSizeMake(_ivSongCover.frame.size.height, _ivSongCover.frame.size.width)];
            }

            [_ivSongCover setImage:iconImage];
        }
    }
}

It seems that itemArtwork is not null. Because if this value is null, then the default cover art image should be used instead.

Here is a screenshot of the result of a blank cover for music enter image description here

In this case, I hope that itemArtwork should be null so that I can use my default image. But in this case it is not zero, worse, it does not even give me anything to display at all. How can I solve this problem.

, . , , , .

, , - ?

: , , itemArtwork , .

, . . !

+4

Source: https://habr.com/ru/post/1606241/


All Articles