我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 代。
谢谢。