我正在开发一个音乐应用程序,其中乐谱通过使用AVPLayer播放的m4v视频文件显示,AVCaptureSession用于预览和记录表演者随着乐谱演奏的视频和音频。
不幸的是,虽然AVCaptureVideoPreviewLayer在显示音乐符号的同时还会显示实时视频,但当我尝试向AVCaptureSession添加音频输入时,AVPlayer会暂停。
我已经尝试使用单独的AVCaptureSession用于预览层和音频记录,但似乎没有什么不同。
我是在尝试做不可能的事情,还是有一种方法可以同时播放视频/音频和录制视频/音频。
据我所知,Skype和Facetime做的是类似的事情(尽管不完全一样)。
发布于 2012-11-02 00:08:32
将音频会话类别设置为正确的属性PlayandRecord。同时将allowmixwithothers设置为yes。
发布于 2013-02-27 03:44:01
尝尝这个。我只是为另一个项目这么做了,而且很管用。
-(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-12-06 03:33:18
我也有同样的问题,但在iOS 7中似乎已经解决了。在iOS 7之前,我可以让AVAudioRecorder与AVPlayer同时工作,但不能让AVCaptureSession与音频一起工作。
https://stackoverflow.com/questions/6176654
复制相似问题