从MP3文件/ ID3标签获取专辑图片 [英] Get album artwork from MP3 file/ID3 tag
本文介绍了从MP3文件/ ID3标签获取专辑图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从MP3文件中获取相册作品。
I'm trying to get the album artwork from a MP3 file.
在这种情况下,我使用 AVAudioPlayer
来播放该文件。
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];
然而 artworkView
不包含任何图像无论如何。
However artworkView
doesn't contain any image whatsoever.
我有点陷入困境。
如果任何人可以通过提供建议来帮助/我如何直接从ID3标签获取艺术作品,这将是非常有用的。
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.
感谢任何帮助。
推荐答案
你必须在这里使用enumerateValuesForProperties是一个示例:
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)];
}
}
}];
这篇关于从MP3文件/ ID3标签获取专辑图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文