iOS 中的后台录音
我广泛搜索了有关如何在后台录制音频的文档,并得出结论:在 plist 文件中指定“音频”可能有效。但是,由于 iOS 4 在内存不足时会终止后台应用程序,因此当我们转换到后台时,我们还必须采取一些措施来减少内存使用量。我们如何减少内存使用?
另外,有人知道在 iOS 上在后台录制音频的可靠方法吗?
我取消选中 Info.plist 文件中显示“应用程序不在后台运行”的框,并
<key> UIBackgroundModes </ key> < array> < string> audio</ string></ array>
在 Info.plist
中添加了 。但是,当我按下“HOME”按钮时,录音就会停止。
我们要实现哪些回调才能知道应用程序已进入后台? 请指教。
I have searched far and wide for documentation on how to record audio in the background and have come to the conclusion that specifying 'audio' in the plist file might work. But, because iOS 4 will terminate background apps when it runs low on memory, we must also take some steps to reduce our memory usage when we transition to the background. How do we reduce our memory usage?
Also, does anybody know a sure shot way of recording audio in the background on iOS??
I unchecked the box in the Info.plist file that says "Application does not run in background" and also added the
<key> UIBackgroundModes </ key> < array> < string> audio</ string></ array>
in Info.plist
. But, the recording stops as soon as I press the "HOME" button.
What callbacks do we implement to know that application has gone to background?
Please advise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以防万一其他人在这里寻找答案,我通过将 UIBackgroundModes 数组添加到 plist 中,将“音频”添加为项目 0 来工作。
我在退出时释放所有内存/控制器,就像退出应用程序一样所以剩下的就是应用程序使用的缓冲区(我已经分配了大约 1Mb,虽然这让我有点紧张,但它似乎有效!)我想降低保真度也会有所帮助,但它似乎按原样工作。
在我的核心音频设置中,我必须将缓冲区大小从 1024 更改为 4096,或者明确设置缓冲区大小...我选择了后者,因为延迟是一个问题。
我还必须确保它不会在退出时通过不启用“不在后台运行”选项来杀死应用程序,但是无论如何,默认情况下这应该是关闭的。
所以我想我回答这个问题是为了让其他人安心,毕竟它不需要太多设置就可以工作。
然而,我在蓝牙设置方面遇到了问题,我猜这是因为缓冲区大小再次发生变化,但无法弄清楚这一点...通过记录回调渲染数据时,只需得到 -50 = 无效属性警告。我猜这是频率/样本大小,但谁知道......稍后会看,但似乎背景现在有效。
Just in case anyone else is looking for an answer here, I got mine working by adding the UIBackgroundModes array to the plist, adding 'audio' as Item 0.
I free up all memory/controllers on exit as you would by quitting the app anyhow so all that is left are the buffers the app uses (I've allocated around 1Mb though which makes me a little nervous however it seems to have worked!) I guess reducing the fidelity would help too but it seems to work as is.
In my core Audio setup I had to either change the buffer size from 1024 to 4096 or explicitly set the buffer size... I opted for the latter as latency was an issue.
I also had to make sure that it didn't kill the app on exit via not enabling the 'Does not run in background' option however this should be off by default anyhow.
So guess I'm answering this for peace of mind for anyone else that it does work with not much setup after all.
I am however experiencing problems with Bluetooth setup, I guess that's because the buffer sizes change again but can't figure this one out... just get -50 = invalid property warning when rendering the data via the recordingCallback. I'm guessing it's the freq/sample size but who knows... will look later but seems like background now works.
除了在plist文件中指定后台记录之外,我们还可以实现applicationDidEnterBackground,它会告诉我们应用程序何时进入后台。在这里,我们应该停止对 UI 的任何更新,因为这会消耗内存,例如更新计时器和均衡器。
调用 applicationWillEnterForeground 将在应用程序返回前台之前调用,以便我们可以恢复我们停止的任何操作。
然后录音在后台进行。它还有助于实现一个中断侦听器(这也可以在后台工作),这样您就不会丢失录音。
Apart from specifying background recording in the plist file, we can implement applicationDidEnterBackground wihch will tell us when the application enters background. Here, we should stop any updates to the UI because that consumes memory for eg, updating a timer and an equalizer.
The call applicationWillEnterForeground will be called just before the app returns to foreground so we can resume whatever we stopped.
The recording then takes place in the background. It would also help to implement an interruption listener(this would work in the backgroud as well) so that you don't lose your recordings.