AVAudioSession AVAudioSessionCategoryRecord
For recording audio; this category silences playback audio. Recording continues with the screen locked.
AVAudioSession AVAudioSessionCategoryRecord example.
Every time when i record the video, i create a session for recording:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord error:nil];
and this was the problem sometimes session takes time to start and recording was delayed by 3-4sec. So, i created the session in viewdidload and make it global and the problem was resolved.
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord error:nil];
and this was the problem sometimes session takes time to start and recording was delayed by 3-4sec. So, i created the session in viewdidload and make it global and the problem was resolved.
Example of [AVAudioSession AVAudioSessionCategoryRecord].
Code corresponding to AudioSession setup
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:&error];
[[AVAudioSession sharedInstance] setActive:YES error:&error];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:&error];
[[AVAudioSession sharedInstance] setActive:YES error:&error];
AVAudioSession AVAudioSessionCategoryRecord example.
It turns out that when using AVAudioSessionCategoryRecord (or equivalently, kAudioSessionCategory_RecordAudio from the C APIs), you must also disable output on the audio unit:
...
// Disable output
err = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, kOutputElement, &disableFlag, sizeof(disableFlag));
if (err != noErr) NSLog(@"Error disabling output for audio unit: %ld", err);
...
// Disable output
err = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, kOutputElement, &disableFlag, sizeof(disableFlag));
if (err != noErr) NSLog(@"Error disabling output for audio unit: %ld", err);