如何从 AVAsset 或 AVAssetTrack 获取文件扩展名

How to get the file extension from an AVAsset or AVAssetTrack

我在 AVAsset 中有一个音频文件(mp3、wav、aiff、...),然后获取 AVAssetTrack

我正在寻找一种从该资产中以 AVFileTypeAudioFileTypeID 等 Apple 格式查找音频文件类型(mp3、wav、aiff 等)的方法?

目前我发现获取音频文件类型的唯一方法是使用 AVAssetTrackformatDescriptions 属性 并获取子类型,如 documentation 但效果不是很好,因为我无法确定我使用的是哪种未压缩格式(wav 或 aiff),因为我只得到 "lpcm" 格式...

无法从 AVAsset 中获取 AVFileType

您是如何获得资产的?您可以尝试转换为 AVURLAsset,获取 URL,最后获取 pathExtension。