Post

Replies

Boosts

Views

Activity

Background music becomes mono when initialising AVAudioSession to AVAudioSessionCategoryPlayAndRecord
Hello. We are writing iPhone application for bikers. This application uses voice communication with user. It need to play sounds and record audio samples from user. Application will be used by bikers when them are driving so they will use headsets. Also our application should not prevent playing background music from other applications (Apple music for example). But we have got some strange bug. When we are initializing Audio session in our application background music from AppleMusic loses quality and became MONO!!! And this is happens ONLY when we use category AVAudioSessionCategoryPlayAndRecord (in AVAudioSessionCategoryPlayback all is OK) and ONLY with headsets ( for example with model Uclear amp pro but not only with it).Code of AudioSession initialization:AVAudioSession* audioSession = [AVAudioSession sharedInstance]; AVAudioSessionCategoryOptions options=AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP | AVAudioSessionCategoryOptionAllowAirPlay; NSError* error=nil; if (![audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:options | AVAudioSessionCategoryOptionMixWithOthers error:&error]) { NSLog(@"Error config play and record: %@",error); }It is strange and definetly not an issue of headset because same headset works well with siri "Always on" option (that also play and capture sounds). We will be gratefull for any helpwith this issue.Full code of sample application that demostrate this bug:/ / / / / / #import "ViewController.h" #import <Foundation/Foundation.h> #import <AVFoundation/AVFoundation.h> @interface ViewController () @end @implementation ViewController - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; / } - (IBAction)configPlay:(id)sender { AVAudioSession* audioSession = [AVAudioSession sharedInstance]; AVAudioSessionCategoryOptions options=0; NSError* error=nil; if (![audioSession setCategory:AVAudioSessionCategoryPlayback withOptions:options | AVAudioSessionCategoryOptionMixWithOthers error:&error]) { NSLog(@"Error config play: %@",error); } } - (IBAction)configPlayAndRecord:(id)sender { AVAudioSession* audioSession = [AVAudioSession sharedInstance]; AVAudioSessionCategoryOptions options=AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP | AVAudioSessionCategoryOptionAllowAirPlay; NSError* error=nil; if (![audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:options | AVAudioSessionCategoryOptionMixWithOthers error:&error]) { NSLog(@"Error config play and record: %@",error); } } - (IBAction)configPlayAndRecordToSpeaker:(id)sender { AVAudioSession* audioSession = [AVAudioSession sharedInstance]; AVAudioSessionCategoryOptions options=AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP | AVAudioSessionCategoryOptionAllowAirPlay; NSError* error=nil; if (![audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:options | AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDefaultToSpeaker error:&error]) { NSLog(@"Error config play and record to speaker: %@",error); } } - (IBAction)activateSession:(id)sender { AVAudioSession* audioSession = [AVAudioSession sharedInstance]; NSError* error=nil; if (![audioSession setActive:true error:&error]) { NSLog(@"Error set active: %@",error); } } - (IBAction)deactivateSession:(id)sender { AVAudioSession* audioSession = [AVAudioSession sharedInstance]; NSError* error=nil; if (![audioSession setActive:false error:&error]) { NSLog(@"Error set inactive: %@",error); } } - (IBAction)sayText:(id)sender { AVSpeechSynthesizer* synthesizer = [[AVSpeechSynthesizer alloc]init]; AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"Hello, how are you? We hail you here!"]; utterance.voice=[AVSpeechSynthesisVoice voiceWithLanguage: @"en-US"]; utterance.pitchMultiplier=1; utterance.rate=0.4; utterance.volume=1; [synthesizer speakUtterance:utterance]; } @end
1
1
1.7k
Oct ’17