1
我在用戶的文檔目錄中有幾個MP3文件,我希望能夠獲得並顯示ID3藝術品標籤。我曾嘗試使用NSURLAsset,但我不確定如何將其轉換爲UIImage或UIImageView!ID3藝術品標籤從MP3文檔目錄iPhone開發
謝謝!
我在用戶的文檔目錄中有幾個MP3文件,我希望能夠獲得並顯示ID3藝術品標籤。我曾嘗試使用NSURLAsset,但我不確定如何將其轉換爲UIImage或UIImageView!ID3藝術品標籤從MP3文檔目錄iPhone開發
謝謝!
您必須使用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));