2012-02-07 6 views
3

저는 오디오와 비디오를 녹음하면서 동시에 오디오를 스피커로 출력 할 수있는 iOS 앱을 만들려고합니다.AVCaptureSession과 오디오 재생을 동시에 오디오/비디오 기록?

녹화 및 미리보기를 수행하려면 비디오 및 오디오 모두에 AVCaptureSession, AVCaptureConnection, 비디오 및 오디오 모두에 각각 AVAssetWriterInput을 사용하고 있습니다. 기본적으로 RosyWriter 예제 코드를 따라이 작업을 수행했습니다.

이 방식으로 녹음을 설정하기 전에 나는 오디오를 재생하기 위해 AVAudioPlayer을 사용하고있었습니다. 나는 (도 기록하지, 단지 미리보기 캡처) 캡처의 중간에 오전 내 AVCaptureAudioDataOutputSampleBufferDelegate 클래스 정류장에 AVAudioPlayer, 내 captureOutput 콜백을 사용하려고하면

자,라고하기.

해결 방법이 있습니까?

캡쳐를 중단하지 않을 오디오를 재생할 때 사용해야하는 다른 하위 서비스가 있습니까?

mc.

+0

이에 대한 모든 솔루션을 기록 할 수있다? – sajwan

+0

답변 : http://stackoverflow.com/a/7219499/2700842 –

답변

1

먼저 AVAudioSession 및 그 카테고리를 설정하십시오. viewDidLoad 방법 예를 들어,

AVAudioSession *session = [AVAudioSession sharedInstance]; 
[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers|AVAudioSessionCategoryOptionDefaultToSpeaker error:nil]; 

따라서 당신은

self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:music_url error:nil]; 
    [self.player setDelegate:self]; 
    [self.player play]; 

BGM

을 재생하고 영화

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]; 
관련 문제