我正在尝试将captureSession / camera添加到视图中。但无论我做什么,它都不会在docker-compose rm
中显示任何内容。它只显示一个空白cameraView
(UIView
。我做错了什么?
变量
cameraView
viewDidLoad中
var captureSession = AVCaptureSession()
var backCamera: AVCaptureDevice?
var frontCamera: AVCaptureDevice?
var captureDevice: AVCaptureDevice?
let stillImageOutput = AVCaptureStillImageOutput()
var previewLayer : AVCaptureVideoPreviewLayer?
let videoOutput = AVCaptureMovieFileOutput()
let devices = AVCaptureDevice.devices()
var cameraView: UIView!
beginSession
setupCamera()
if backCamera != nil {
beginSession(backCamera!)
}
cameraView = UIView(frame: CGRectMake(0, 0, self.view.frame.width, self.view.frame.height))
cameraView.backgroundColor = UIColor.redColor()
self.view.addSubview(cameraView)
**setupCamera**
func setupCamera() {
captureSession.sessionPreset = AVCaptureSessionPresetHigh
// Loop through all the capture devices on this phone
for device in devices {
// Make sure this particular device supports video
if device.hasMediaType(AVMediaTypeVideo) {
// Finally check the position and confirm we've got the back camera
if device.position == AVCaptureDevicePosition.Back {
backCamera = device as? AVCaptureDevice
}
if device.position == AVCaptureDevicePosition.Front {
frontCamera = device as? AVCaptureDevice
}
}
if device.hasMediaType(AVMediaTypeAudio) {
print(device)
}
}
}