비디오를 녹화하고 동영상을 파일로 올바르게 출력 할 수 있습니다. 그러나 일부 오디오 재생 AVAudioPlayer 사용하려고 할 때 비디오 녹화 (비디오 출력 없음) 문제가 있습니다. AVCaptureSession과 AVAudioPlayer를 동시에 사용할 수 없다는 의미입니까? 다음은 캡처 세션을 만들고 오디오를 재생하는 코드입니다. 비디오 캡처가 먼저 시작된 다음 캡처하는 동안 일부 오디오를 재생하려고합니다. 어떤 도움을 주셔서 감사합니다.함께 AVCaptureSession 및 AVAudioPlayer 사용
코드 (오디오) 비디오를 녹화 할 수있는 캡처 세션을 생성 - 출력을 .mov 인 파일 : 오디오를 재생
- (void)addVideoInput
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
//... also some code for setting up videoDevice/frontCamera
NSError *error;
AVCaptureDeviceInput *videoIn = [AVCaptureDeviceInput
deviceInputWithDevice:frontCamera error:&error];
AVCaptureDeviceInput *audioIn = [AVCaptureDeviceInput
deviceInputWithDevice:audioDevice error:&error];
if (!error) {
if ([captureSession canAddInput:audioIn])
[captureSession addInput:audioIn];
else
NSLog(@"Couldn't add audio input.");
if ([captureSession canAddInput:videoIn])
[captureSession addInput:videoIn];
else
NSLog(@"Couldn't add video input.");
}
- (void)addVideoOutput
{
AVCaptureMovieFileOutput *m_captureFileOutput = [[AVCaptureMovieFileOutput alloc] init];
[captureSession addOutput:m_captureFileOutput];
[captureSession startRunning];
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSMutableString *filePath = [NSMutableString stringWithString:@"Movie.mov"];
NSString* fileRoot = [docDir stringByAppendingPathComponent:filePath];
NSURL *fileURL = [NSURL fileURLWithPath:fileRoot];
AVCaptureConnection *videoConnection = NULL;
for (AVCaptureConnection *connection in [m_captureFileOutput connections])
{
for (AVCaptureInputPort *port in [connection inputPorts])
{
if ([[port mediaType] isEqual:AVMediaTypeVideo])
{
videoConnection = connection;
}
}
}
[videoConnection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
[m_captureFileOutput startRecordingToOutputFileURL:fileURL recordingDelegate:self];
[m_captureFileOutput release];
}
코드,이 기능은 비디오 캡처 세션 동안 호출입니다. 이 기능을 호출하지 않으면 비디오가 녹화되고 .mov 파일에 저장할 수 있습니다. 그러나이 함수를 호출하면 출력 .mov 파일이 없습니다.
- (void)playAudio
{
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"AudioFile" ofType:@"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath];
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
[fileURL release];
self.audioPlayer = newPlayer;
[newPlayer release];
[audioPlayer setDelegate:self];
[audioPlayer prepareToPlay];
[audioPlayer play];
}
안녕 HappyAppDeveloper,이 동일한 문제에 붙어 있습니다. setupAudioSession에서 동일한 초기화를 수행 할 때와 동일한 작업을 수행하지만 캡처 세션은 항상 중지됩니다. 이게 iOS6에 부러 졌는지 알아? iOS 5 및 6에서 완벽하게 작동하는 – kungfoo
! 저장 한 나의 베이컨, 감사 !!!!!!!!!!! – SpaceDog
ARC를 사용하는 경우 오디오 플레이어를 "강"으로 선언해야합니다. 그렇지 않으면 조기에 방출 될 수 있으며 소리가 나지 않습니다. – Sten