【问题标题】:ID3 Artwork Tags from MP3 In Documents Directory iPhone Development文档目录中 MP3 中的 ID3 艺术品标签 iPhone 开发
【发布时间】:2011-08-09 22:46:26
【问题描述】:

我在用户的文档目录中有几个 MP3 文件,我希望能够获取并显示 ID3 艺术品标签。我曾尝试使用 NSURLAsset,但不确定如何将其转换为 UIImage 或 UIImageView!

谢谢!

【问题讨论】:

    标签: iphone uiimage mp3 id3 artwork


    【解决方案1】:

    你必须使用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));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-18
      • 1970-01-01
      • 1970-01-01
      • 2010-09-25
      • 2011-09-12
      • 1970-01-01
      • 2011-12-08
      • 1970-01-01
      相关资源
      最近更新 更多