I'm trying to extract all the available meta-data from mp3 files (amongst others) using the AVKit framework.
I first get the "common" metadata with something like:
let asset = AVAsset(url: URL(fileURLWithPath: path))
for item in asset.commonMetadata {
if let commonKey = item.commonKey {
if let storageKey = stringValueKeys[commonKey] {
and that works fine.
Note that I look up a storageKey
stored in the stringValueKeys
hash to determine whether I'm interested in this item and then to store it into an internal database for caching.
Then I process id3 tags separately (they are not returned by asset.commonKey
) using:
for item in asset.metadata(forFormat: .id3Metadata) {
if let key = item.key as? AVMetadataKey {
if let storageKey = stringValueKeys[key] {
I can retrieve the data correctly, but the keys that are returned do not match up with those defined by the framework!?
item.key
contains the 3 letter keys as defined by the ID3 standard (e.g. TT1
, TAL
, but AVMetadataKey
defines 4 letter keys, e.g. AVMetadataKey.id3MetadataKeyAlbumTitle
= TALB
.
I can't find a way of translating between the 4 and the 3 letter codes.
Any help would be greatly appreciated.