如何使用 AVAssetWriter 导出 mp3 文件

How to export mp3 file with AVAssetWriter

我正在尝试使用 AVAssetWriter.

将我的资产导出为 .mp3 文件

下面是我如何创建它的实例:

writer = try! AVAssetWriter(url: outputURL,
                            fileType: AVFileType.mp3)

不幸的是,它抛出错误:

[AVAssetWriter initWithURL:fileType:error:] Invalid file type UTI.

Available file types are: com.scenarist.closed-caption, org.w3.webvtt, public.aiff-audio, com.apple.m4v-video, org.3gpp.adaptive-multi-rate-audio, com.apple.m4a-audio, com.microsoft.waveform-audio, com.apple.coreaudio-format, public.mpeg-4, com.apple.itunes-timed-text, com.apple.quicktime-movie, public.aifc-audio

我在 macOS 10.15 上 运行 这段代码。 我很难相信不支持导出 mp3 文件。谁能指导我如何让它发挥作用?

I find it hard to believe that there's no support for exporting an mp3 file

克服你的困难,相信它。由于复杂的版权问题,Apple 没有许可提供任何创建 MP3 文件的本机功能。你可能会找到一些可以做到这一点的第三方库,但你不会用 AVAssetWriter 做到这一点。