I wrote a app to record video from iPhone. It work fine but have one big problem. When AVCaptureSession start running and user try to play audio from thier library(iPod). This action will make AVCaptureSession terminate. Have any idea can prevent user try to play audio or solve this problem?
this is my code:
videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput *videoDeviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:videoDevice error:nil];
AVCaptureDeviceInput *audioDeviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioDevice error:nil];
movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
captureSession = [[AVCaptureSession alloc] init];
[captureSession beginConfiguration];
[captureSession setSessionPreset:AVCaptureSessionPresetHigh];
[captureSession addInput:videoDeviceInput];
[captureSession addInput:audioDeviceInput];
[captureSession addOutput:movieFileOutput];
[captureSession commitConfiguration];
[captureSession startRunning];
This worked for me:
- (void)setupAudio {
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
UInt32 doSetProperty = 1;
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty);
[[AVAudioSession sharedInstance] setActive: YES error: nil];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With