How to play sound during a phone call from the application

I want to use the same function in the application as VOYPI in iOS.

Play background sound during a call.

I used the code below to play the background sound during a call.

Link for reference application here .

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:self.bgAudioFileName ofType: @"mp3"]; NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath ]; myAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil]; myAudioPlayer.numberOfLoops = -1; NSError *sessionError = nil; // Change the default output audio route AVAudioSession *audioSession = [AVAudioSession sharedInstance]; // get your audio session somehow [audioSession setCategory:AVAudioSessionCategoryMultiRoute error:&sessionError]; BOOL success= [audioSession overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&sessionError]; [audioSession setActive:YES error:&sessionError]; if(!success) { NSLog(@"error doing outputaudioportoverride - %@", [sessionError localizedDescription]); } [myAudioPlayer setVolume:1.0f]; [myAudioPlayer play]; } 

This code will play sound on the current carrier call using avaudioplayer.

I set the category AVAudioSessionCategoryMultiRoute.

With this category, the receiver will be able to listen to background sound during the current call of the operator from the application.

But there was one problem with this, it would create an echo on the receiver side.

Help me in this code.

+5
source share

All Articles