开发者

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 initReco开发者_如何学Pythonrder];

    [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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜