iphone - AUGraph stops running after phone call interrupt in iOS -
i'm using augraph , ausampler convert midi signals audio. app runs fine there's problem if app interrupted i.e. phone call or timer. after interruption augraph stops running , there isn't sound. way sound again restart app. i'm using standard method handle interruption:
[[nsnotificationcenter defaultcenter] addobserver: self selector: @selector(handleinterruption:) name: avaudiosessioninterruptionnotification object: [avaudiosession sharedinstance]]; when there's interruption handleinterruption method called:
// if system interrupts audio session - kill volume -(void) handleinterruption: (nsnotification *) notification { nsdictionary *interuptiondict = notification.userinfo; nsinteger interuptiontype = [[interuptiondict valueforkey:avaudiosessioninterruptiontypekey] intvalue]; if (interuptiontype == avaudiosessioninterruptiontypebegan) { [self setaudiosessionactive: no]; [self stopaugraph]; } else if (interuptiontype == avaudiosessioninterruptiontypeended) { [self setaudiosessionactive: yes]; [self startaugraph]; } } here methods start , stop augraph
-(void) startaugraph { checkerror(augraphstart(_audiograph), "failed start audio graph"); } -(void) stopaugraph { boolean isrunning = false; // check see if graph running. checkerror(augraphisrunning(_audiograph, &isrunning), "error trying querying whether graph running"); // if graph running, stop it. if (isrunning) { checkerror(augraphstop(_audiograph), "failed stop audio graph"); } } here setaudiosessionactive method:
-(void) setaudiosessionactive: (bool) active { nserror *audiosessionerror = nil; bool success = [_audiosession setactive:active error:&audiosessionerror]; if (!success) { nslog (@"error activating audio session!"); } } i've put break point in render callback can confirm augraph isn't running. has experienced problem before? there else have augraph running again? in advance!
i've been having terrible troubles bug. think i've found workaround:
since nsnotifications don't trigger when returning after call interruption, in appdelegate's -applicationwillenterforeground:method check see if there interruption caused enter background (i set flag when avaudiosessioninterruptionnotification posted avaudiosessioninterruptiontypebegan interruption type key) , if call method in object controlling augraph runs following:
boolean isrun = false; augraphisrunning(myaugraph, &isrun); if (isrun) { nslog(@"end interruption augraph running"); augraphstop(myaugraph);// kick start augraph! augraphstart(myaugraph); //restart boolean isinit = false; augraphisinitialized(processinggraph, &isinit); if (!isinit) { nslog(@"augraph not initd'"); osstatus result = augraphinitialize(processinggraph); if (result != noerr) { nslog(@">>can't init graph"); } } } else { nslog(@"end interruption augraph not running"); } the key seems stopping , restarting augraph. far, operates correctly when call comes in or when app takes on loudspeaker/mic can pick left off in app.
the re-initialising of augraph never seems executed nor isrun true i've left in anyway. hope helps situation, took me days crack 1 , i'm hoping continues work instead of being coincidence! 4 hours , counting far!
Comments
Post a Comment