Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I start a Record iOS audio session in the background?

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, NULL), "AudioQueueStart failed");

I get this error:

Error: AudioQueueStart failed (-12985)

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.

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.

like image 424
audioBackgrounder Avatar asked May 30 '13 14:05

audioBackgrounder


People also ask

Can voice recorder run in the background?

Secretly Record Audio on Your Android Phone. The built-in audio recorder on Android usually supports background recording. What that means is that you can turn on recording, lock the screen, and it'll continue to capture the audio.

Can iOS apps use microphone in background?

Certain apps can use your iPhone's microphone to learn what you watch, listening in the background for audio signals playing from gaming consoles, TV shows, streaming programs, and advertisements.


1 Answers

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.

like image 85
audioBackgrounder Avatar answered Nov 05 '22 00:11

audioBackgrounder