【发布时间】:2011-08-09 22:46:26
【问题描述】:
我在用户的文档目录中有几个 MP3 文件,我希望能够获取并显示 ID3 艺术品标签。我曾尝试使用 NSURLAsset,但不确定如何将其转换为 UIImage 或 UIImageView!
谢谢!
【问题讨论】:
标签: iphone uiimage mp3 id3 artwork
我在用户的文档目录中有几个 MP3 文件,我希望能够获取并显示 ID3 艺术品标签。我曾尝试使用 NSURLAsset,但不确定如何将其转换为 UIImage 或 UIImageView!
谢谢!
【问题讨论】:
标签: iphone uiimage mp3 id3 artwork
你必须使用AVAsset 类:
例如:
NSString *mp3Path = [[NSBundle mainBundle] pathForResource:@"audio-file" ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:mp3Path];
AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
for (NSString *format in [asset availableMetadataFormats]) {
for (AVMetadataItem *item in [asset metadataForFormat:format]) {
if ([[item commonKey] isEqualToString:@"artwork"]) {
NSData *data = [(NSDictionary *)[item value] objectForKey:@"data"];
UIImageView *img = [[[UIImageView alloc] initWithImage:[UIImage imageWithData:data]] autorelease];
[self.view addSubview:img];
continue;
}
NSLog(@"%@", item);
}
}
NSLog(@"> Duration = %.2f seconds", CMTimeGetSeconds(asset.duration));
【讨论】: