-1
스위프트를 프로그래밍하고 배우는 것이 처음입니다. 카메라를 사용하는 응용 프로그램을 만들었지 만 전면 카메라로 전환하려고 시도 할 때 오류가 발생했습니다 스레드 1w : EXC_BREAKPOINT 비디오를 녹화하려고합니다.스위프트 3에서 카메라를 교체 할 때 기록 오류가 발생했습니다.
오류 내가 좀이 오류 내 프로그램에 붙어 선
if (connection?.isVideoOrientationSupported)!{connection?.videoOrientation = currentVideoOrientation()}
에서 FUNC startRecording()
발생합니다. pls 도움!
enum CameraType {
case front
case back
}
var camera = CameraType.front
func switchCamera() -> Bool {
captureSession.stopRunning()
previewLayer?.removeFromSuperlayer()
captureSession = AVCaptureSession()
captureSession.sessionPreset = AVCaptureSessionPresetHigh
var captureDevice:AVCaptureDevice! = AVCaptureDevice.defaultDevice(withDeviceType: .builtInWideAngleCamera, mediaType: AVMediaTypeVideo, position: .front)
if (camera == CameraType.front) {
captureDevice = AVCaptureDevice.defaultDevice(withDeviceType: .builtInWideAngleCamera, mediaType: AVMediaTypeVideo, position: .front)
camera = CameraType.back
} else {
captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
camera = CameraType.front
}
let input = try? AVCaptureDeviceInput(device: captureDevice)
if captureSession.canAddInput(input) {
captureSession.addInput(input)
activeInput = input
}
if captureSession.canAddOutput(movieOutput) {
captureSession.addOutput(movieOutput)
}
print("Abidi")
return true
}
func reloadCamera() {
if switchCamera() {
setupPreview()
startSession()
}
view.addSubview(dismissButton)
dismissButton.anchor(top: view.topAnchor, left: nil, bottom: nil, right: view.rightAnchor, paddingTop: 12, paddingLeft: 0, paddingBottom: 0, paddingRight: 12, width: 50, height: 50)
view.addSubview(frontCameraButton)
frontCameraButton.anchor(top: view.topAnchor, left: view.leftAnchor, bottom: nil, right: nil, paddingTop: 12, paddingLeft: 12, paddingBottom: 0, paddingRight: 0, width: 35, height: 35)
}
func viewDidAppear(animated: Bool) {
reloadCamera()
}
func startCapture() {
startRecording()
}
func tempURL() -> URL? {
let directory = NSTemporaryDirectory() as NSString
if directory != "" {
let path = directory.appendingPathComponent(NSUUID().uuidString + ".mp4")
return URL(fileURLWithPath: path)
}
return nil
}
func startRecording() {
if movieOutput.isRecording == false {
let connection = movieOutput.connection(withMediaType: AVMediaTypeVideo)
if (connection?.isVideoOrientationSupported)! {
connection?.videoOrientation = currentVideoOrientation()
}
if (connection?.isVideoStabilizationSupported)! {
connection?.preferredVideoStabilizationMode = AVCaptureVideoStabilizationMode.auto
}
let device = activeInput.device
if (device?.isSmoothAutoFocusSupported)! {
do {
try device?.lockForConfiguration()
device?.isSmoothAutoFocusEnabled = false
device?.unlockForConfiguration()
} catch {
print("Error setting configuration: \(error)")
}
}
outputURL = tempURL()
movieOutput.startRecording(toOutputFileURL: outputURL, recordingDelegate: self)
}
else {
stopRecording()
}
}
func stopRecording() {
if movieOutput.isRecording == true {
movieOutput.stopRecording()
}
}
감사합니다 당신이 아주 많이?! 내 프로그램이 현재 작동 중입니다. 정말 감사. – elrafael16