同时录制带有AVCaptureSession和回放音频的音频/视频?
问题描述:
我试图创建一个iOS应用程序,可以记录音频和视频,同时将音频输出到扬声器。同时录制带有AVCaptureSession和回放音频的音频/视频?
要进行录制和预览,我使用AVCaptureSession
,AVCaptureConnection
分别用于视频和音频,以及各为AVAssetWriterInput
用于视频和音频。我基本上是通过遵循RosyWriter示例代码实现的。
此前以这种方式建立记录,我用AVAudioPlayer
播放音频。现在
,如果我在拍摄(甚至没有记录,只是捕捉预览)的中间,并尝试使用AVAudioPlayer
,我captureOutput
回调对我AVCaptureAudioDataOutputSampleBufferDelegate
类停止获取调用。
是否有解决方法?
有另一种较低层次的服务,我应该用它来进行播放音频不会停止我的拍摄?
MC。
答
您先设置AVAudioSession
及其类别。例如,在viewDidLoad
方法,
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers|AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];
因此,你可以玩BGM
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:music_url error:nil];
[self.player setDelegate:self];
[self.player play];
,并记录电影
self.captureSession = [[AVCaptureSession alloc] init];
/* ... addInput AVCaptureDeviceInput AVMediaTypeVideo & AVMediaTypeAudio */
/* ... addOutput */
[self.captureSession startRunning];
AVCaptureMovieFileOutput *m_captureFileOutput =[self.captureSession.outputs objectAtIndex:0];
[m_captureFileOutput startRecordingToOutputFileURL:saveMovieURL recordingDelegate:self];
任何解决这个? – sajwan 2013-01-17 18:54:34
答案:http://stackoverflow.com/a/7219499/2700842 – 2013-12-10 04:28:28