1
在此無法找到向上最新的答案:AVCaptureDevice貶值至AVCaptureDeviceDiscoverySession使用前置攝像頭
- (void)viewDidLoad {
[super viewDidLoad];
AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetHigh;
AVCaptureDevice *device = [self frontCamera];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
[session addInput:input];
AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
newCaptureVideoPreviewLayer.frame = self.view.bounds;
[self.view.layer addSublayer:newCaptureVideoPreviewLayer];
[self.view bringSubviewToFront:_logo];
[session startRunning];
}
- (AVCaptureDevice *)frontCamera {
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices) {
if ([device position] == AVCaptureDevicePositionFront) {
return device;
}
}
return nil;
}
的NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
折舊,並要求使用AVCaptureDeviceDiscoverySession
。我怎樣才能正確實現AVCaptureDeviceDiscoverySession這個代碼? 我只想使用前置攝像頭。 謝謝
的可能的複製[如何獲得前置攝像頭,後置攝像頭和音頻AVCaptureDeviceDiscoverySession(https://stackoverflow.com/questions/39894630/how -to-GET-前置攝像頭,背面攝像頭和音頻與 - avcapturedevicediscoverysess) – Yeheshuah