Reputation: 10460
I'm trying to get the album artwork from a MP3 file.
In this case I use AVAudioPlayer
to play the file.
Here's the code that I thought would get the album artwork:
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
doesn't contain any image whatsoever.
I'm a little bit stuck.
If any one could help by providing suggestions to where/how I can get the artwork directly from the ID3 tag, that would be of great use.
Any help appreciated.
Upvotes: 4
Views: 4132
Reputation: 120
You have to use enumerateValuesForProperties here is a sample:
[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)];
}
}
}];
Upvotes: 4