3

I having problem on displaying the item artwork of MPMediaItem.

Here is the code for setting the music 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 isn't null. Because if it is null, then my default music cover image should be used instead.

Here is the screenshot of the result of a blank music coverenter image description here

In this case, I am hoping that itemArtwork should be a null so that I could use my default cover image. But in this case, it isn't null, worse, it doesn't even give me anything to display at all. How can I solve this one.

I am thinking of adding another logic, which is detecting the dominant colour of the current image used. If it consist of exactly no colour at all or just plain clear colour, then I would conclude that there is no music cover at all, and make use of the default one.

However, I want to know is there anything wrong with my code?

Take note: This song does not really have a cover image, BUT I wish that the itemArtwork should return a null, but it doesn't.

I hope I made myself clear. Please help. Thanks in advance!

JLT
  • 3,052
  • 9
  • 39
  • 86

0 Answers0