Recording Chunked Audio in Background iOS

I am trying to figure out a way to record audio in the background of an iOS application and have it streamed to the server.

I have pretty much got this working for when the app is in the foreground. I use AVAudioRecorder to record input for X seconds. Once I get the callback that this has finished, I record for another X seconds. Each recording session gets stored to a different file and I send these files asynchronously to the server.

However, this doesn't seem to work while my app goes into background mode.

When going into the background, the current record session continues recording until the X seconds are up, however my app gets suspended, before I can start another recording session.

Any ideas?

Here's the code for my callback:

- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)aRecorder successfully:(BOOL)flag {
    NSLog(@"hello");

    [self initRecorder];

    [recorder recordForDuration:5];

}

You can't restart recording in the background.

So use the Audio Queue or Audio Unit RemoteIO APIs instead, which will give you smaller "chunks" (callback buffer blocks) of audio without stopping the audio recording.

Concatenate small audio callback chunks into larger file chunks if needed for your network protocol.


Background audio playing is supported with multitasking but it's not very clear that background audio recording is. However, I have not tried it. The Audio Unit API might let you continue to record audio while the application is in the background. However, this is kind of a trick and I Imagine it might get pulled out at some point.

链接地址: http://www.djcxy.com/p/79024.html

上一篇: 无法在iOS上以后台模式重新启动中断的音频输入队列

下一篇: 在背景iOS中录制分块音频