2011-05-30 40 views
4

我正在开发音乐应用程序,其中音乐符号通过使用AVPLayer播放的m4v视频文件显示,并且AVCaptureSession用于预览和录制演奏者的视频和音频分数。将音频输入添加到AVCaptureSession中停止AVPlayer

不幸的是,虽然AVCaptureVideoPreviewLayer在显示音乐符号时显示实况视频,但当我尝试向AVCaptureSession添加音频输入时,AVPlayer会暂停。

我已经尝试使用单独的AVCaptureSession的预览图层和音频记录,但这似乎没有什么区别。

我想要做不可能的事,或者有没有办法同时播放视频/音频和录制视频/音频。

据我所见,Skype和Facetime可以做类似的事(虽然不完全一样)。

回答

0

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

0

试试这个。我只是做了它的另一个项目和它的作品

-(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

我有同样的问题,但它似乎被固定在iOS的7此前的iOS 7,我可以得到AVAudioRecorder与AVPlayer同时工作,但不带音频的AVCaptureSession。