如何在多个应用程序启动之间分割音频编码?
我的应用程序需要将大量音频数据编码为 M4A 文件。我目前正在使用 AVAssetWriter,它工作正常,只是需要几分钟来对所有数据进行编码。 我不想要求用户保持应用程序运行直到进程完成,而是想在应用程序终止时暂停编码并继续重新启动。
不幸的是,AVAssetWriter 似乎不支持这一点,因为它总是在初始化时创建一个新文件。
您知道我可以使用其他任何 API 吗?也许是第三方库?
My app needs to encode a large amount of audio data to an M4A file. I am currently using AVAssetWriter, which works fine, except that it takes a few minutes to encode all the data.
Instead of asking the user to keep the app running until the process has finished, I would like to pause the encoding when the app terminates and continue on relaunch.
Unfortunately, AVAssetWriter doesn't seem to support this, as it always creates a new file when initializing.
Do you know any other APIs that I could use? Maybe a third-party library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这正是后台处理的目的。只要你能在10分钟内完成,你就可以使用
beginBackgroundTaskWithExpirationHandler:
请求系统让你在用户切换应用后继续运行。请参阅在后台完成有限长度任务 在 iOS 应用程序编程指南中。这不仅是最容易使用的,而且会提供最佳的用户体验。您面临的唯一问题是音频文件是否可能以不可恢复的方式花费超过 10 分钟。如果确实有可能,那么您将需要另一个解决方案。
This is exactly what background processing is intended for. As long as you can complete within 10 minutes, you can use
beginBackgroundTaskWithExpirationHandler:
to ask the system to let you keep running after the user switches applications. See Completing a Finite-Length Task in the Background in the iOS Application Programming Guide. Not only is this the easiest to use, but it'll give the best user experience.The only issue you'd face is if it's possible for an audio file to take longer than 10 minutes in a non-resumable way. If that's a real possibility, then you'll need another solution.