In order to keep an eye, on an earphone possibly plugged or unplugged, in my iPhone app and react properly; I use the following kind of code, in a few of my classes:
- (void)viewDidLoad
{
[super viewDidLoad];
…..
routeChangeID=kAudioSessionProperty_AudioRouteChange;
AudioSessionAddPropertyListener(routeChangeID,rvcHandleRouteChange,(__bridge void *)(self));
}
…….
void rvcHandleRouteChange(void *inUserData,AudioSessionPropertyID inPropertyID,
UInt32 inPropertyValueSize,const void *inPropertyValue)
{
NSLog(@"Hi rvcHandleRouteChange has been called.");
if (inPropertyID!=kAudioSessionProperty_AudioRouteChange) NSLog(@"WRONG CALL!!!");
// Do some useful work ….
}
That seems to work rather well, except in one case where the rvcHandleRouteChange call back function gets called with no apparent reason. Even with the test to filter the wrong calls, none of them appear to be "WRONG CALLs". I mean it gets called without me to plug or unplug any earphone. As a consequence this gives me a lot of trouble.
Anyone has an idea of why this could happen?