0
votes

So I successfully created an app, in this case it's a VOIP app using linphone sip library. I was doing some tests where I want a WAV file to always play, regardless of whether my app is in the foreground or background. I was able to successfully implement this test with the following code:

NSString * resourcePath = [NSString stringWithFormat:@"%@/myres/sounds/oldphone-mono.wav",[[NSBundle mainBundle] resourcePath]];



    ringer = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath] error:nil];

    [ringer setNumberOfLoops:100];



    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

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



    [ringer setVolume:1.0];



    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;

    AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);


        [ringer play];

I think this is pretty straightforward code, because I copied it from another stack overflow answer. I also had to do something to my plist file to allow for audio background playing.

So the problem is that a function from some 3rd party software (in this case LinPhone SIP Library's Receive Incoming Call Function) that when fired will prevent my app from playing my sound file in background.

As an example, here's a test case:

  • start up my app and i hear the ringing wav file, that's good
  • i put the app in background mode and i still hear the ringing wav file, that's good
  • i bring the app back into focus, i still hear the ringing, that's good
  • i trigger the linphone receive call function, the ringing still continues because i'm in foreground, that's good
  • i put the app in background mode, the ringing stops, that's not good

So I suspect that linphone has done something to the avaudioplayer/avaudiosession, such that i can no longer play in background. So my question is, can anyone hazard a guess as to what linphone may have done to prevent my app from playing sound in the background, and how i might get around this issue?

ADDITIONAL NOTES

I even tried to instantiate a new avaudioplayer every second while the app was in the background. But it couldn't override whatever linphone has done to silence the playing of audio.

1

1 Answers

1
votes

It appears that Linphone messed with the AVAudioSession Category Options. I had to reset the category option to AVAudioSessionCategoryOptionMixWithOthers in order to get around the problem like so:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];