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代創作
謝謝。
'recordingView'只是我的'MainViewController'中的'UIView'。 改變了這一點,但沒有修復它... – tonekk
你也應該在init之後啓動你的會話。 '[newSession startRunning];' – yinkou
好吧,我忘了複製它。 我認爲問題可能在其他地方... 這裏是整個項目(如果允許...):http://www21.zippyshare.com/v/26365272/file.html 它並不多,只有5個課程左右。 – tonekk