Jaffer Sheriff
Jaffer Sheriff

Reputation: 1564

AVAudioRecorder not resuming after AVAudioSessionInterruptionNotification

I used AVAudioRecorder to record audio. I added AVAudioSessionInterruptionNotification to my viewcontroller to pause recording during interruption.

 - (void)viewDidLoad 
   {      
     [super viewDidLoad];
     // Other Stuffs
      [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(interrupted:)
                                             name:AVAudioSessionInterruptionNotification
                                           object:nil];
 }



-(void)interrupted:(NSNotification *) sender
   {
        if(recorder.isRecording)
          {
             // Code To Update UI
             [recorder pause];
          }
   }     

Question 1: During interruption interruped method is called twice. Why?. During first call the recorder is nil. And during second call recoder.isRecording is NO. Why ?

Question 2: If application becomes action after receiving interruption, [recorder record] does not resume recording to file. But rather it starts to record it as new audio file. How to resolve this ?

Upvotes: 0

Views: 327

Answers (1)

Hamster8
Hamster8

Reputation: 21

Interrupted calls 2 times cause it notify you about begin interuption and about end. Look notification userInfo (your sender is notification object), it contains object for key AVAudioSessionInterruptionTypeKey, which contains one of values: AVAudioSessionInterruptionTypeBegan or AVAudioSessionInterruptionTypeEnded . You can analyze it and deside when pause and when resume. But remember, second call is not necessary, it writed in documentation and it is true, i checked. System can deside when you can resume you work and when you don't need it.

About recorder there is too little info.

Upvotes: 0

Related Questions