ユーザーのドキュメント ディレクトリに複数の MP3 ファイルがあり、ID3 アートワーク タグを取得して表示できるようにしたいと考えています。NSURLAsset を使用してみましたが、それを UIImage または UIImageView に変換する方法がわかりません!
ありがとう!
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));