gpt4 book ai didi

ios - 无法使用 AVCaptureSession 获得任何视频预览

转载 作者:行者123 更新时间:2023-11-28 23:12:11 26 4
gpt4 key购买 nike

我像这样设置我的 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];

然后我在我的 View 中添加了一个预览层:

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是怎么定义的?二、

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

没有意义。 (你试图在自己的层内的自己的层之上添加一个层 -> duh?)请尝试使用 [recordingView.layer addSublayer:layer];

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

关于ios - 无法使用 AVCaptureSession 获得任何视频预览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7902225/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com