Iphone 将音频输入添加到AVCaptureSession会停止AVPlayer

Iphone 将音频输入添加到AVCaptureSession会停止AVPlayer,iphone,avplayer,avcapturesession,Iphone,Avplayer,Avcapturesession,我正在开发一个音乐应用程序,其中通过使用AVPLayer播放的m4v视频文件显示乐谱,并使用AVCaptureSession预览和录制演奏者随乐谱播放的视频和音频 不幸的是,尽管AVCaptureVideoPreviewLayer在显示乐谱的同时显示实时视频,但当我尝试向AVCaptureSession添加音频输入时,AVPlayer会暂停 我曾尝试在预览层和录音中使用单独的AVCaptureSession,但这似乎没有什么区别 我是在尝试做不可能的事情,还是有办法同时播放视频/音频和录制视频/

我正在开发一个音乐应用程序,其中通过使用AVPLayer播放的m4v视频文件显示乐谱,并使用AVCaptureSession预览和录制演奏者随乐谱播放的视频和音频

不幸的是,尽管AVCaptureVideoPreviewLayer在显示乐谱的同时显示实时视频,但当我尝试向AVCaptureSession添加音频输入时,AVPlayer会暂停

我曾尝试在预览层和录音中使用单独的AVCaptureSession,但这似乎没有什么区别

我是在尝试做不可能的事情,还是有办法同时播放视频/音频和录制视频/音频


据我所知,Skype和Facetime做了类似的事情(尽管不完全相同)。

将音频会话类别设置为正确的属性Play和Record。同时将allowmixwithothers设置为yes。

试试这个。我只是为另一个项目做的,而且很有效

-(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];
}

我也有同样的问题,但它似乎在iOS 7中得到了修复。在iOS 7之前,我可以让AVAudioRecorder与AVPlayer同时工作,但不能让AVCaptureSession与音频同时工作