Question

I want to get the ISRC code for Local itunes songs. I can get the metaData by the following codes:

 MPMusicPlayerController *mp= mp = [MPMusicPlayerController applicationMusicPlayer];
  NSURL *assetURL = [mp.nowPlayingItem valueForProperty:MPMediaItemPropertyAssetURL];
    AVAsset *asset = [AVAsset assetWithURL:assetURL];
    NSArray *metadata = [asset commonMetadata];
        for ( AVMetadataItem* item in metadata ) {
            NSString *key = [item commonKey];
            NSString *value = [item stringValue];
            NSLog(@"extra iptions %@",[item extraAttributes]);
            NSLog(@"key = %@, value = %@", key, value);

            NSLog(@"keyspace and Local %@   %@",[item keySpace],[item key]);

        }

But I am really wondering about how to get ISRC(International Standard Record Coding).

Was it helpful?

Solution

Try this (warning: typed into browser)

NSArray *metadata = [asset metadataForFormat:AVMetadataFormatID3Metadata];
if (metadata == nil) {
    NSLog(@"No ID3 metadata for asset: %@", asset);
}
// From https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVFoundation_ID3Constants/Reference/reference.html

NSArray *filteredMetadata = [AVMetadataItem metadataItemsFromArray:metadata withKey:AVMetadataID3MetadataKeyInternationalStandardRecordingCode keySpace:nil];
AVMetadataItem *item = [filteredMetadata firstObject];
if (item != nil) {
    NSLog(@"ISRC: %@", item.stringValue);
} else {
    NSLog(@"No ISRC found for: %@", asset);
}

EDIT: I should mention, the reason your original code didn't print the value of the ISRC is because the ISRC is not part of the common metadata space, and won't be included in the array returned by [asset commonMetadata]. The ISRC key is specific to ID3 metadata, so if your asset does not have ID3 metadata associated with it, you will be unable to retrieve that information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top