2

I've a audio file (mp3, wav, aiff, ...) in an AVAsset then get the AVAssetTrack.

I'm looking for a way of finding the audio file type (mp3, wav, aiff, ...) from this asset in a Apple format like AVFileType or AudioFileTypeID?

For the moment the only way I find to get the audio file type is to use formatDescriptions property of AVAssetTrack and get the subType as showed in the documentation but it doesn't work very well since I cannot determine which uncompressed format I have (wav or aiff) because I just get "lpcm" format...

Isn't possible to get the AVFileType from an AVAsset?

DEADBEEF
  • 1,930
  • 2
  • 17
  • 32

1 Answers1

2

How are you acquiring the asset? You can try casting to AVURLAsset, get the URL, and finally the pathExtension.

George Brown
  • 1,134
  • 10
  • 25
  • Thanks indeed it's a solution. Btw could we get the audio file format in Apple format like `AVFileType` or `AudioFileTypeID`? – DEADBEEF Nov 06 '17 at 13:11
  • 1
    You can compare the UTI to the extension, https://medium.com/@francishart/swift-how-to-determine-file-type-4c46fc2afce8 or https://stackoverflow.com/questions/31243371/path-extension-and-mime-type-of-file-in-swift (last answer I think is more correct) – George Brown Nov 06 '17 at 13:32
  • Thanks George, it was what I was looking for! When I get the uti string I can create an AVFiletype with init(rawValue:) – DEADBEEF Nov 06 '17 at 13:54