var captureSession: AVCaptureSession!
var videoPreviewLayer: AVCaptureVideoPreviewLayer!
viewDidLoad
퍼미션 체크, 요청
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .notDetermined:
break
case .restricted:
break
case .denied:
if let url = URL(string: UIApplication.openSettingsURLString) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
break
case .authorized:
break
@unknown default:
break
}
AVCaptureDevice.requestAccess(for: .video) {
flag in
}
do {
try AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: [.allowBluetooth])
try AVAudioSession.sharedInstance().setActive(true)
} catch {
return
}
captureSession = AVCaptureSession()
let videoDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front)
let audioDevice = AVCaptureDevice.default(.builtInMicrophone, for: .audio, position: .unspecified)
guard let videoDeviceInput = try? AVCaptureDeviceInput(device: videoDevice!),
let audioDeviceInput = try? AVCaptureDeviceInput(device: audioDevice!),
captureSession.canAddInput(videoDeviceInput),
captureSession.canAddInput(audioDeviceInput) else {
return
}
captureSession.addInput(videoDeviceInput)
captureSession.addInput(audioDeviceInput)
videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
videoPreviewLayer.videoGravity = .resizeAspect
videoPreviewLayer.connection?.videoOrientation = .portrait
videoPreviewLayer.frame = previewView.layer.bounds
previewView.layer.addSublayer(videoPreviewLayer)
captureSession.startRunning()
viewWillDisappear
self.captureSession.stopRunning()
'프로그래밍 > iOS,macOS' 카테고리의 다른 글
[Metal] 이미지 렌더링~ 텍스처 표시 (0) | 2021.02.03 |
---|---|
[Metal] 이미지 렌더링~ 사각형 그리기 (0) | 2021.02.03 |
[Metal] AR 얼굴인식 및 obj 렌더링 (0) | 2021.01.16 |
[Metal] Render to Texture (0) | 2020.12.27 |
UIButton selected + highlighted image (0) | 2020.12.02 |
Codable for Dictionary (0) | 2020.06.10 |
UITableView , UICollectionView (1) | 2020.04.14 |
[iOS] 키보드를 따라 올라오는 뷰 (0) | 2020.04.08 |
[iOS] Google SignIn (0) | 2020.03.30 |
xcode 11. ios13 미만, storyboard 없이 시작 (0) | 2020.03.29 |