Closed ETmanwenhan closed 2 years ago
也行需要额外添加锁设备代码:
do {
try ni.device.lockForConfiguration()
ni.device.videoZoomFactor = zoomFactor
ni.device.unlockForConfiguration()
} catch {
zl_debugPrint("调整焦距失败 \(error.localizedDescription)")
}
也行需要额外添加锁设备代码:
do {
try ni.device.lockForConfiguration()
ni.device.videoZoomFactor = zoomFactor
ni.device.unlockForConfiguration()
} catch {
zl_debugPrint("调整焦距失败 \(error.localizedDescription)")
}
也行需要额外添加锁设备代码:
do { try ni.device.lockForConfiguration() ni.device.videoZoomFactor = zoomFactor ni.device.unlockForConfiguration() } catch { zl_debugPrint("调整焦距失败 \(error.localizedDescription)") }
你添加完这块代码后,还会crash吗
也行需要额外添加锁设备代码:
do { try ni.device.lockForConfiguration() ni.device.videoZoomFactor = zoomFactor ni.device.unlockForConfiguration() } catch { zl_debugPrint("调整焦距失败 \(error.localizedDescription)") }
你添加完这块代码后,还会crash吗
我还没详细测试过,我是根据崩溃提示调整的。有空我再测试一下
也行需要额外添加锁设备代码:
do { try ni.device.lockForConfiguration() ni.device.videoZoomFactor = zoomFactor ni.device.unlockForConfiguration() } catch { zl_debugPrint("调整焦距失败 \(error.localizedDescription)") }
你添加完这块代码后,还会crash吗
我在我的设备上测试没发现崩溃问题,不管是否添加lockForConfiguration;
但是线上设备出现崩溃问题, ZLPhotoBrowser version: e.g. 4.2.1 Device: e.g. iPhone 8 Plus Device version: e.g. iOS 12.4.1 Xcode version: e.g. Xcode 13.1
这个问题重现了,在iPhone 6,我修复方案如下:
@objc func switchCameraBtnClick() {
do {
guard !self.restartRecordAfterSwitchCamera else {
return
}
guard let currInput = self.videoInput else {
return
}
var newVideoInput: AVCaptureDeviceInput?
if currInput.device.position == .back, let front = self.getCamera(position: .front) {
newVideoInput = try AVCaptureDeviceInput(device: front)
} else if currInput.device.position == .front, let back = self.getCamera(position: .back) {
newVideoInput = try AVCaptureDeviceInput(device: back)
} else {
return
}
let zoomFactor = currInput.device.videoZoomFactor
if let ni = newVideoInput {
self.session.beginConfiguration()
self.session.removeInput(currInput)
if self.session.canAddInput(ni) {
self.session.addInput(ni)
self.videoInput = ni
//ni.device.videoZoomFactor = zoomFactor
self.setVideoZoomFactor(zoomFactor) // 解决iPhone6拍照切换摄像头崩溃问题
} else {
self.session.addInput(currInput)
}
self.session.commitConfiguration()
if self.movieFileOutput.isRecording {
let pauseTime = self.animateLayer.convertTime(CACurrentMediaTime(), from: nil)
self.animateLayer.speed = 0
self.animateLayer.timeOffset = pauseTime
self.restartRecordAfterSwitchCamera = true
}
}
} catch {
zl_debugPrint("切换摄像头失败 \(error.localizedDescription)")
}
}
ZLPhotoBrowser version: 4.2.1 Device: iPhone 6 Device version: iOS 12.5.2 Xcode version: Xcode 13.1
修复该问题,麻烦通知一下,谢谢大神!
下个版本会把这个ni.device.videoZoomFactor = zoomFactor
代码去掉,切换镜头重置缩放系数
这是来自QQ邮箱的假期自动回复邮件。 您好,谢谢你联系我。我会尽快给您回复。
Issue Description
*** -[AVCaptureDevice setVideoZoomFactor:] May not be called without first successfully gaining exclusive ownership of the device using -lockForConfiguration:
Description and Steps
0 Thread
NSGenericException *** -[AVCaptureDevice setVideoZoomFactor:] May not be called without first successfully gaining exclusive ownership of the device using -lockForConfiguration: 解析原始 0 CoreFoundation ___exceptionPreprocess + 228 2 AVFoundation -[AVCaptureFigVideoDevice setVideoZoomFactor:] + 316 3 papaya_anchor switchCameraBtnClick (:0)
4 papaya_anchor switchCameraBtnClick (:0)
5 UIKitCore -[UIApplication sendAction:to:from:forEvent:] + 96
22 libswiftUIKit.dylib _$s5UIKit17UIApplicationMainys5Int32VAD_SpySpys4Int8VGGSgSSSgAJtF + 168 23 papaya_anchor main (PAAlbumRequester.swift:0) 24 libdyld.dylib _start + 4
Info
ZLPhotoBrowser version: e.g. 4.2.1 Device: e.g. iPhone 8 Plus Device version: e.g. iOS 12.4.1 Xcode version: e.g. Xcode 13.1
Configuration code of
ZLPhotoConfiguration