how to resume recording after interruption occured in iphone?

前端 未结 4 1249
长发绾君心
长发绾君心 2020-12-15 11:26

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,

- (v         


        
4条回答
  •  执笔经年
    2020-12-15 11:57

    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);
    

提交回复
热议问题