Просто используйте AudioToolbox API:
func audioFileInfo(url: URL) -> NSDictionary? {
var fileID: AudioFileID? = nil
var status:OSStatus = AudioFileOpenURL(url as CFURL, .readPermission, kAudioFileFLACType, &fileID)
guard status == noErr else { return nil }
var dict: CFDictionary? = nil
var dataSize = UInt32(MemoryLayout<CFDictionary?>.size(ofValue: dict))
guard let audioFile = fileID else { return nil }
status = AudioFileGetProperty(audioFile, kAudioFilePropertyInfoDictionary, &dataSize, &dict)
guard status == noErr else { return nil }
AudioFileClose(audioFile)
guard let cfDict = dict else { return nil }
let tagsDict = NSDictionary.init(dictionary: cfDict)
return tagsDict
}
Пример вывода:
- 0 : 2 elements
* key : artist
* value : Blue Monday FM
- 1 : 2 elements
* key : title
* value : Bee Moved
- 2 : 2 elements
* key : album
* value : Bee Moved
- 3 : 2 elements
* key : approximate duration in seconds
* value : 39.876
- 4 : 2 elements
* key : source encoder
* value : reference libFLAC 1.2.1 win64 200807090