5

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

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

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

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

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

4

3 回答 3

0

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

于 2012-11-01T16:08:31.850 回答
0

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];
}
于 2013-02-26T19:44:01.373 回答
0

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

于 2013-12-05T19:33:17.697 回答