I m facing this error while managing audio session manually.
[LyfCameraPicker recorder:didInitializeAudioInSession:error:]:2355 - Failed to initialize audio in record session: *\ -[AVAssetWriterInput initWithMediaType:outputSettings:sourceFormatHint:] 3 is not a valid channel count for Format ID 'aac '. Use kAudioFormatProperty_AvailableEncodeNumberChannels (<AudioToolbox/AudioFormat.h>) to enumerate available channel counts for a given format.
AVAudioSession *session1 = [AVAudioSession sharedInstance];
[session1 setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionAllowBluetooth error:nil];
[session1 setActive:YES error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
dispatch_async( dispatch_get_main_queue(), ^{
// Add code here to update the UI/send notifications based on the
// results of the background processing
});
// this is added because, after video captured, app will navigate to SCVideoPlayerViewController.m file. Where i m calling [self stopBackGroundMusic] method to stop back music and to play captured video's audio sound. And is user come back to camera screen it will resume background music.
I m facing this error while managing audio session manually.
**
**
Added Code in App Delegate : `
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions{ dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
});
return YES; }
// this is added because, after video captured, app will navigate to SCVideoPlayerViewController.m file. Where i m calling [self stopBackGroundMusic] method to stop back music and to play captured video's audio sound. And is user come back to camera screen it will resume background music.
}
-(void)resumeBackgroundMusic { NSError *activationError = nil; [[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&activationError]; }
-(void)stopBackGroundMusic { NSError *activationError = nil; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionAllowBluetooth error:nil];
}`
I am initializing SCRecorder in following method.
`-(void)initCoreCam { _recorder = [SCRecorder recorder]; _recorder.initializeSessionLazily = NO; _recorder.automaticallyConfiguresApplicationAudioSession = NO;
// _recorder.audioEnabled = YES; _recorder.delegate = self; _recorder.autoSetVideoOrientation = YES; _recorder.audioConfiguration.enabled = YES;
}
` //===================
`- (void) prepareCamera { if (_recorder.session == nil) {
} `
After this, i am calling pause and stopRunning method in viewWillDisaper methiod.
`- (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated];
} `
Then i am dismiss camera and again open camera at that i am facing above mentioned error.