如何在后台开始录制 iOS 音频会话? [英] How do I start a Record iOS audio session in the background?

查看:103
本文介绍了如何在后台开始录制 iOS 音频会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用程序在后台唤醒但不是最前沿后启动 kAudioSessionCategory_RecordAudio(例如在重大位置更改期间,我看到商店中的其他应用程序这样做,所以我知道这是可能的).但是,每当我尝试像这样开始音频会话时

I'm trying to start a kAudioSessionCategory_RecordAudio after my app is woken up in the background but not forefront (like during a significant location change, I have seen other apps in the store do this so I know it is possible). However whenever I try to start the audio session like so

CheckError(AudioQueueStart(queue,空值),"AudioQueueStart 失败");

我收到此错误:

错误:AudioQueueStart 失败 (-12985)

所以我读了它,但唯一的建议是将音频会话设置为活动 AudioSessionSetActive(YES) 但这也会因 '!cat' 错误而失败.显然,您可以尝试切换音频会话的活动状态,但这对我不起作用.

So I read up on that but only suggestion is setting the audio session to active AudioSessionSetActive(YES) but that also fails with a '!cat' error. Apparently you can try to toggle the active state of the audio session but that hasn't worked for me.

我设置了音频背景模式 plist 标志并在我的应用程序处于最前沿时启动音频会话,然后切换到另一个应用程序工作(显示红色条表示它正在录制).它只是开始音频会话,而应用程序不是最前沿的问题.

I have the audio background mode plist flag set and starting an audio session while my app is forefront then switching to another app works (shows the red bar showing that it is recording). Its just starting the audio session while the app isn't forefront is the issue.

有没有人有示例项目我可以看看在后台启动录音音频会话的演示?

Does anyone have a sample project I could look at demonstrating starting a recording audio session in the background?

注意:我正在寻找一种使用音频队列的解决方案,因为我需要缓冲区中的音频,而不是文件.

Note: I am looking for a solution that uses audio queues as I need the audio in buffers, not a file.

推荐答案

事实证明,如果您只是将音频多任务处理标志添加到 info.plist 并添加适当的重要位置更改 API.您可以查看 https://github.com/benvium/SpeakHere 以获取 SpeakHere 的更新版本,因为 Apple好久没更新了.

It turns out that Apple's SpeakHere sample code with some modifications will start recording audio in the background if you just add the audio multitasking flag to info.plist and add the appropriate significant location change APIs. You might look https://github.com/benvium/SpeakHere for an updated version of SpeakHere since Apple hasn't updated it in awhile.

这篇关于如何在后台开始录制 iOS 音频会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆