2014-12-29 32 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中,就是這樣!