Adding audio input to AVCaptureSession stops AVPlayer

I am developing a music application in which music notation is displayed through m4v video files played using AVPLayer, and AVCaptureSession is used to preview and record both the video and the sound of the artist playing along with the score.

Unfortunately, although AVCaptureVideoPreviewLayer displays live video while music notation is displayed, when I try to add an audio input to AVCaptureSession, then AVPlayer pauses.

I tried using a separate AVCaptureSession for the preview and audio layer, but that doesn't seem to be much different.

I'm trying to do the impossible, or is there a way to play video / audio and record video / audio at the same time.

As far as I can see, Skype and Facetime do similar (though not quite the same) things.

+4
source share
3 answers

Set the audio session category to the desired property, PlayandRecord. Also set allowmixwithothers to yes.

0
source

Try it. I just did it for another project and it works

-(IBAction)beepingSound2 { //do this so that we can hear the scream and record the movie too [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil]; UInt32 doSetProperty = 1; AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty); [[AVAudioSession sharedInstance] setActive: YES error: nil]; [myAudioPlayer1 stop]; NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"long_beep" ofType: @"mp3"]; NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath]; myAudioPlayer1 = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil]; [myAudioPlayer1 play]; } 
0
source

I had the same problem, but it seems to be fixed in iOS 7. Prior to iOS 7, I can get AVAudioRecorder to work simultaneously with AVPlayer, but not AVCaptureSession with sound.

0
source

All Articles