2014-12-29 2 views
0

와 비디오를 녹화 나는 startRecordingToOutputFileURL 호출 할 때 : recordingDelegate : 방법, 그것은 didFinishRecordingToOutputFileAtURL 대리자 메서드 호출을, 그래서 시작하지 않고 완료!내가 세션, 장치, 입력과 출력을 만들었지 만 한 AVFoundation

이것은

-(void)viewWillAppear:(BOOL)animated { 
[super viewWillAppear:animated]; 

AVCaptureSession *session = [[AVCaptureSession alloc] init]; 
[session setSessionPreset:AVCaptureSessionPresetPhoto]; 

AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 


AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&error]; 

if ([session canAddInput:deviceInput]) { 
[session addInput:deviceInput]; 
} 

AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; 

[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; 
CALayer *rootLayer = [[self view] layer]; 
[rootLayer setMasksToBounds:YES]; 
CGRect frame = self.view.frame; 

[previewLayer setFrame:frame]; 

[rootLayer insertSublayer:previewLayer atIndex:0]; 

_movieFileOutput = [[AVCaptureMovieFileOutput alloc] init]; 

if ([session canAddOutput:movieFileOutput]) { 
    [session addOutput:movieFileOutput]; 
} 

[session startRunning]; 
} 
-(void)buttonClicked { 
[_movieFileOutput startRecordingToOutputFileURL:url recordingDelegate:self]; 
} 

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput 
didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL 
     fromConnections:(NSArray *)connections 
      error:(NSError *)error { 
    //This method is getting called when I press the button 
    NSLog(@"Finished Recording"); 

} 

그래서 내 코드가 잘못된 것입니다 .. 내 코드? 나는 무엇이 있 었는가?

감사합니다.

+0

AVCaptureSessionPresetPhoto – Andy

답변

1

마지막으로 작동했습니다.

문제는 URL입니다. 나는 그것들이 작동하지 않는 많은 URL을 시도했다. NSDocumentsDirectory에 있어야한다.