Muting audio from background apps

Home Forums OpenEars Muting audio from background apps

Viewing 5 posts - 1 through 5 (of 5 total)

  • Author
    Posts
  • #1025441
    OT
    Participant

    What is the recommended way to initiate OE (and the underlying AVAudioSession) so that any background audio from the other apps is muted? I see in OEContinuousAudioUnit.m that AVAudioSession is initialized with AVAudioSessionCategoryOptionMixWithOthers option. Is there a way to override that? (given the nature of the OE framework, it may make more sense that this defaults to no mixing)

    Thanks!

    #1025445
    Halle Winkler
    Politepix

    The next version will let you override this setting. It is definitely the correct default setting but also needs to be easily overridden.

    #1025697
    Halle Winkler
    Politepix

    OK, there are some more finely-grained control over the AVAudioSession initialization in OpenEars and plugins 2.04 which are out now.

    #1026395
    OT
    Participant

    Thanks, I had to chance to try it now and it works as expected.

    #1026632
    wfilleman
    Participant

    Hi Halle,

    It’s Wes again :) It’s been awhile, but my users are still getting great value out of OE.

    Upgraded to 2.041 to address the memory growth issue some of my users were seeing and I got bit by something I “fixed” in previous releases. Not sure if I ever posted about this, but in relation to this post about how the AVAudioSession works on init, there’s an undesirable side effect in OEContinuousAudioUnit.m when the app resumes from background.

    Namely what happens is on resume from background, OE sees an audioSession interruption Type Ended which could be due to something in my code (not sure, but it doesn’t matter). The problem is if the user never has turned on OE (voice recognition) OE just goes ahead and set the active audio session in the handleInterruption call of OEContiniuousAudioUnit.m

    What happens is that the background music the user was playing is killed and they are confused because they never turned on voice recognition.

    How I fixed it for myself, and I’m presenting it here because I think this should be merged into the main release, is to see if the self.audioUnitState is kAudioUnitIsStarted before setting the AVAudioSession to Active. This prevents OE from stepping on the AudioSession if it’s not actually turned on.

    Here’s the code. Note that I surrounded the additions with /* MOBILINC ADDITIONS

    – (void)handleInterruption:(NSNotification *)notification {

    NSInteger interruptionPhase = [[[notification userInfo] valueForKey:AVAudioSessionInterruptionTypeKey] intValue];

    if (interruptionPhase == AVAudioSessionInterruptionTypeBegan) {
    if(openears_logging == 1) NSLog(@”The Audio Session was interrupted.”);

    NSDictionary *userInfoDictionary = @{@”OpenEarsNotificationType”: @”AudioSessionInterruptionDidBegin”}; // Send notification to OEEventsObserver.
    NSNotification *notification = [NSNotification notificationWithName:@”OpenEarsNotification” object:nil userInfo:userInfoDictionary];
    [[NSNotificationCenter defaultCenter] performSelectorOnMainThread:@selector(postNotification:) withObject:notification waitUntilDone:YES];

    }

    if (interruptionPhase == AVAudioSessionInterruptionTypeEnded) {

    if(openears_logging == 1) NSLog(@”The Audio Session interruption is over.”);

    NSDictionary *userInfoDictionary = @{@”OpenEarsNotificationType”: @”AudioSessionInterruptionDidEnd”}; // Send notification to OEEventsObserver.
    NSNotification *notification = [NSNotification notificationWithName:@”OpenEarsNotification” object:nil userInfo:userInfoDictionary];
    [[NSNotificationCenter defaultCenter] performSelectorOnMainThread:@selector(postNotification:) withObject:notification waitUntilDone:YES];

    /*
    * MOBILINC ADDITIONS
    */
    if (self.audioUnitState == kAudioUnitIsStarted) {
    /*
    * MOBILINC ADDITIONS
    */

    NSError *error = nil;

    error = [self setAllAudioSessionSettings];

    [[AVAudioSession sharedInstance] setActive:YES error:&error];

    if (error != nil) NSLog(@”AVAudioSession set active failed with error: %@”, error);

    /*
    * MOBILINC ADDITIONS
    */
    }
    /*
    * MOBILINC ADDITIONS
    */

    }
    }

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.