2011-10-26 31 views
0

設置我AVCaptureSession像這樣:不能得到任何視頻預覽與AVCaptureSession

AVCaptureSession *newSession = [[AVCaptureSession alloc] init]; 
AVCaptureDevice *camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 

NSError *error = nil; 

AVCaptureDeviceInput *newInput = [[AVCaptureDeviceInput alloc] initWithDevice:camera error:&error]; 


if(error) { 
    NSLog([error localizedDescription]); 

} 

AVCaptureMovieFileOutput *newOutput = [[AVCaptureMovieFileOutput alloc] init]; 


if([newSession canAddInput:newInput]) 
    [newSession addInput:newInput]; 
if ([newSession canAddOutput:newOutput]) 
    [newSession addOutput:newOutput]; 

[self setSession:newSession]; 
[self setInput:newInput]; 
[self setOutput:newOutput]; 

然後我添加了一個預覽層,我的觀點:

AVCaptureVideoPreviewLayer *layer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[recorder session]]; 

[layer setBounds:[recordingView bounds]]; 
[layer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; 

[[recordingView layer] insertSublayer:layer above:[recordingView layer]]; 

但我不會得到任何預習。

我在iOS 5上用iPod Touch第4代創作

謝謝。

回答

2

首先,你的recordingView是如何定義的? 二,

[[recordingView layer] insertSublayer:layer above:[recordingView layer]]; 

是沒有意義的。 (你正試圖在自己的圖層上面添加一層自己的圖層 - >嗯?) 嘗試[recordingView.layer addSublayer:layer];來代替。

您在註釋中發佈的項目使用歸零弱指針。標記你的房產強大,而一切正常。

+0

'recordingView'只是我的'MainViewController'中的'UIView'。 改變了這一點,但沒有修復它... – tonekk

+0

你也應該在init之後啓動你的會話。 '[newSession startRunning];' – yinkou

+0

好吧,我忘了複製它。 我認爲問題可能在其他地方... 這裏是整個項目(如果允許...):http://www21.zippyshare.com/v/26365272/file.html 它並不多,只有5個課程左右。 – tonekk