0

Sorry for a long introduction of the problem.

In my app I am using recording audio and set category to record

AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryRecord error:&err];

When an ad network shows interstitial ad, after that recording is all mute (there is no sound in recording). As this happens with users on live network only, I am not able to reproduce it at my end.

In the log I get ">>>> frameSizeChanged = 4096" from users which points to webkit code https://github.com/WebKit/webkit/blob/master/Source/WebCore/platform/audio/ios/AudioDestinationIOS.cpp

This looks like some process is holding on to Audio Unit setup and not letting it go even after it is completed(freed / released).

Question: Is there a way to clean up audio unit setup by some other module? Just need to reset so that recording can work again in app after the ad is shown.

I have tried to capture "AVAudioSessionInterruptionNotification" but there is none. Any help is really appreciated

Amit
  • 69
  • 1
  • 1
  • 7

1 Answers1

1

You need to handle your audio system getting interrupted. Many things can cause your audio to get interrupted: - Receive a phone call while your app runs - Other app running uses audio - iOS needs to play a sound - etc

Your app needs to detect this interruption as your app's audio session will be essentially muted. Once the interruption is done, you need to restart your session.

Set up your listener as the first step in your session setup

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yourInterruptionListener:) name:AVAudioSessionInterruptionNotification object:nil];

In your interruption listener, handle the cases of getting interrupted and handle restarting your session

-(void) yourInterruptionListener:(NSNotification*) aNotification
{
    NSLog(@"Interruption happened");
    NSDictionary *interruptionDict = aNotification.userInfo;
    NSNumber* interruptionTypeValue = [interruptionDict valueForKey:AVAudioSessionInterruptionTypeKey];
    NSUInteger interruptionType = [interruptionTypeValue intValue];
    if ( interruptionType == AVAudioSessionInterruptionTypeBegan)
    {
        // stop your audio session here
        AVAudioSession *session = [AVAudioSession sharedInstance];
        NSError *errorInAudio   = nil;
        [session setActive:NO error:&errorInAudio];
    }
    else if ( interruptionType == AVAudioSessionInterruptionTypeEnded )
    {
        // Your interruption ended, restart the session
        // call or paste your session startup code here
    }
    else if ( interruptionType == AVAudioSessionInterruptionOptionShouldResume )
    {


    }
    else
    {
                NSLog(@"Some other interruption");
    }

}

If you need to simulate the behavior of your users, start your app then call your self from a different phone. It will definitely interrupt your audio.

jaybers
  • 1,991
  • 13
  • 18
  • Thanks for the suggestion. I do have interruption handler which gets called when app goes to background or during other interruptions. Though when the app faces this problem of silent recording, it is not getting called so I am assuming that it is not because of the interruption. – Amit Oct 02 '15 at 11:06
  • Going to background is a app lifecycle state that can be captured. Did you create add an observer for AVAudioSessionInterruptionNotification? – jaybers Oct 02 '15 at 14:44
  • Exactly similar way as you have described but no luck. – Amit Oct 04 '15 at 18:21