0

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

谢谢。

4

1 回答 1

2

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

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

没有意义。(您正在尝试在自己的图层内的自己的图层上方添加一个图层 -> 呃?)尝试[recordingView.layer addSublayer:layer];改为。

您在评论中发布的项目使用归零弱指针。相反,将您的属性标记为强,一切正常。

于 2011-10-26T12:10:20.390 回答