Search code examples
iosobjective-ccocoa-touchmedia-playermpmediaitem

How to add Genre Artwork into UITableViewCell in iOS?


I am trying to add Genre Artwork into my UITableViewCell in iOS like following pic.

enter image description here

I think there is no built-in artwork for Genre. I am using MediaPlayer Framework and i can add MPMediaItemPropertyArtwork. But i have no idea how to add Genre artwork.

How can i do it? Any Ideas are also welcome.


Solution

  • You could search through all available songs, pull out the MPMediaItemPropertyGenre string.

    From there you could get the list of available genres and then you could either have your own custom artwork for the genre or you could get a random album artwork from a song in that genre using MPMediaItemPropertyArtwork.

    Note this is untested code. In your cellForRowAtIndexPath do something like this.

    MPMediaItem *mItem = (MPMediaItem *)[rockSongs objectAtIndex:indexPath.row];
    
    MPMediaItemArtwork *artWork = [mItem valueForProperty:MPMediaItemPropertyArtwork];
    
    cell.imageView.image = [artWork imageWithSize:CGSizeMake(30, 30)];
    

    If you want to add your own custom artwork you could just set the cell image.

    cell.imageView.image = [UIImage imageNamed:@"Rock"];