Get album art from MP3 / ID3 file

I am trying to get album art from an MP3 file.

In this case, I use AVAudioPlayer to play the file.

Here is the code I thought would get the album cover:

 MPMusicPlayerController *controller = [MPMusicPlayerController applicationMusicPlayer]; MPMediaItem *current = controller.nowPlayingItem; MPMediaItemArtwork *artwork = [current valueForProperty:MPMediaItemPropertyArtwork]; UIImage *artwork2 = [artwork imageWithSize:artwork.bounds.size]; [artworkView setImage:artwork2]; 

However, artworkView does not contain any image.

I'm a little stuck.

If someone can help by suggesting where / how I can get the cover directly from the ID3 tag, that would be very helpful.

Any help was appreciated.

+4
source share
1 answer

You should use enumerateValuesForProperties, here is an example:

 [item enumerateValuesForProperties:[NSSet setWithObjects:MPMediaItemPropertyTitle,MPMediaItemPropertyAlbumTitle,MPMediaItemPropertyArtist,MPMediaItemPropertyArtwork,nil] usingBlock:^(NSString *property, id value, BOOL *stop) { if ([property isEqualToString:MPMediaItemPropertyTitle]){ if (value){ titre=value; }else { titre=@ ""; } } if ([property isEqualToString:MPMediaItemPropertyArtist]){ if(value){ artist=value; }else { artist=@ ""; } } if ([property isEqualToString:MPMediaItemPropertyArtwork]){ MPMediaItemArtwork *art=value; if (art!=nil){ imgV.image=[art imageWithSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.width)]; } } }]; 
+4
source

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


All Articles