- This topic has 4 replies, 3 voices, and was last updated 8 years, 8 months ago by wfilleman.
-
AuthorPosts
-
April 16, 2015 at 11:56 pm #1025441OTParticipant
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!
April 17, 2015 at 11:35 am #1025445Halle WinklerPolitepixThe next version will let you override this setting. It is definitely the correct default setting but also needs to be easily overridden.
May 9, 2015 at 5:48 pm #1025697Halle WinklerPolitepixOK, there are some more finely-grained control over the AVAudioSession initialization in OpenEars and plugins 2.04 which are out now.
July 15, 2015 at 11:47 pm #1026395OTParticipantThanks, I had to chance to try it now and it works as expected.
August 20, 2015 at 2:12 am #1026632wfillemanParticipantHi 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
*/}
} -
AuthorPosts
- You must be logged in to reply to this topic.