2011-08-09 36 views

回答

3

您必須使用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));