Get album artwork from ID3 tag/Convert function from Java to Objective-C

后端 未结 4 883
借酒劲吻你
借酒劲吻你 2021-02-06 18:54

I\'ve got the following question to ask:

How do you compile taglib with an iOS application?

I\'m a bit confused as I added the folder into my project, tried to c

4条回答
  •  我在风中等你
    2021-02-06 19:14

    This is just the answer of @hatfinch above but fixed and now working.

    - (void)artworksForFileAtPath:(NSString *)path block:(void(^)(NSArray *artworkImages))block
    {
        NSURL *url = [NSURL fileURLWithPath:path];
        AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
        NSArray *keys = [NSArray arrayWithObjects:@"commonMetadata", nil];
        [asset loadValuesAsynchronouslyForKeys:keys completionHandler:^{
             NSArray *artworks = [AVMetadataItem metadataItemsFromArray:asset.commonMetadata
                                                                withKey:AVMetadataCommonKeyArtwork
                                                               keySpace:AVMetadataKeySpaceCommon];
    
             NSMutableArray *artworkImages = [NSMutableArray array];
             for (AVMetadataItem *item in artworks) {
                 NSString *keySpace = item.keySpace;
                 if ([keySpace isEqualToString:AVMetadataKeySpaceID3]) {
                     NSDictionary *d = [item.value copyWithZone:nil];
                     [artworkImages addObject:[UIImage imageWithData:[d objectForKey:@"data"]]];
                 } else if ([keySpace isEqualToString:AVMetadataKeySpaceiTunes]) {
                     [artworkImages addObject:[UIImage imageWithData:[item.value copyWithZone:nil]]];
                 }
             }
             if(block) {
                 block(artworkImages);
             }
         }];
    }
    

提交回复
热议问题