I am developing a music app where musical notation is displayed via a m4v video file played out using AVPLayer and an AVCaptureSession is used to preview and record both the video and audio of the performer playing along to the score.
Unfortunately, although the AVCaptureVideoPreviewLayer displays live video whilst the musical notation is displayed, when I try to add an audio input to the AVCaptureSession then the AVPlayer pauses.
I have tried using separate AVCaptureSession's for the preview layer and the audio recording as well, but that seems to make little difference.
Am I trying to do the impossible, or is there a way to playout video/audio and record video/audio at the same time.
As far as I can see S开发者_如何学JAVAkype and Facetime do similar (although not exactly the same) things.
Set the audio session category to the right property, PlayandRecord. Also set the allowmixwithothers to yes.
Try this. 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];
}
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 audio.
精彩评论