9

I am working on an audio recorder application, it is working perfectly fine.

But I'm stuck with the problem of interruption. When a call comes,

- (void)audioRecorderBeginInterruption:(AVAudioRecorder *)recorder

then this method is called and the recording is paused.

And if the user rejects the call:

- (void)audioRecorderEndInterruption:(AVAudioRecorder *)recorder

Then here I want to resume the recording from the point where it was interrupted. But when I call the record method again, the recording starts with a new file.

colithium
  • 10,269
  • 5
  • 42
  • 57
Jitendra Singh
  • 2,103
  • 3
  • 17
  • 26
  • Please post the code you are using to start/stop/pause recording. Are your releasing every time the AVAudioRecorder object and instantiating a new one? This may explain why each time you start recording using a different file. – Massimo Cafaro Nov 10 '09 at 09:57
  • Fyi, I have built a small sample app that shows how the End Int is not working properly and have logged a call with Apple on this issue. It has been with them for > 2 months and have heard nothing. – ort11 May 11 '12 at 13:34

4 Answers4

7

The problem is solved!

I have re-written the recording code to avoid this problem. I used AudioQueues, basically the backend code is the same of SpeakHere application with some minor changes. Provided two more apis in it:

-(void)resume
{
    AudioQueueStart(queueObject, NULL);
}

-(void)pause
{
    AudioQueuePause(queueObject);
}

In AudioRecorder class. The basic purpose being to avoid the recording setup which is done in record method.

Setup the interrupt callback and then use this pause and resume methods appropriately in the callback. Also take care to set active the audio session based on whether your application needs it or not.

Hope this helps someone out there.

EDIT:

Audio interrupt listener callback:

void interruptionListenerCallback (void *inUserData, UInt32 interruptionState)
{
    if (interruptionState == kAudioSessionBeginInterruption) 
    {
        [self.audioRecorder pause];
    } 
    else if (interruptionState == kAudioSessionEndInterruption) 
    {
        // if the interruption was removed, and the app had been recording, resume recording
        [self.audioRecorder resume];
    }
}

Listening for audio interruption:

AudioSessionInitialize(NULL, NULL, interruptionListenerCallback, self);
Raj Pawan Gumdal
  • 7,390
  • 10
  • 60
  • 92
2

The OS is probably stopping the AVAudioRecorder during the interruption. You can either present the two or more files as a single recording to the user, or you can use AudioQueue to write your code for handling interruptions (as well as saving audio data to a file).

lucius
  • 8,665
  • 3
  • 34
  • 41
0

I tried to do this a while ago and came to the conclusion that it couldn't be done properly; the operating system itself won't let you do it. Maybe that's changed in 3.1.2, but when I tried in 3.0 it just wouldn't work.

Jason B
  • 667
  • 1
  • 9
  • 16
0

To handle the interruption, you have to use AVAudioSessionDelegate methodes instead of AVAudioRecorderDelegate methods.This is the code sample for handling interruption:

/*=================================================================
 Interruption Handling Method during Recording
 ==================================================================*/

- (void) beginInterruption 
{
 if(self.recorder)
        {
  //Method to handle UI
 }
}

- (void) endInterruption
{

 NSError *err = noErr;
 [[AVAudioSession sharedInstance] setActive: YES error: &err];
 if(err != noErr)
 {
   NSLog([err description]);
 }
        //method to handle UI
} 

First method automatically deactivate the audio session.So,in second method,you have to reactivate the audio session.First method will pause the recording and when interruption ends you can resume with second method.I have tried this on version 3.0 and upper version.

Leo
  • 37,640
  • 8
  • 75
  • 100