我正在尝试捕捉图像:
var stillImageOutput = AVCaptureStillImageOutput()
stillImageOutput!.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]
[...]
if let videoConnection = stillImageOutput.connectionWithMediaType(AVMediaTypeVideo) {
videoConnection.videoOrientation = AVCaptureVideoOrientation.Portrait
println("enabled = \(videoConnection.enabled)") //enabled = true
println("active = \(videoConnection.active)") //active = true
stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: {
(sampleBuffer, error) in
if error != nil {
println(error)
}
})
}
大部分时间都能正常运作!
但有时我在拨打captureStillImageAsynchronouslyFromConnection
时会收到错误:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation couldn't be completed."
UserInfo=0x14682110 {NSLocalizedDescription=The operation couldn't be completed.,
NSUnderlyingError=0x1676be30 "The operation couldn't be completed.
(OSStatus error -16400.)",
NSLocalizedFailureReason=An unknown error has occured (-16400)}
我只是想预料会发生此错误。我尝试过测试videoConnection.enabled
和videoConnection.active
,但两者似乎都与错误无关......
在拍摄照片之前,我需要检查以确保一切正常吗?
答案 0 :(得分:5)
我也收到了与您相同的错误消息。经过大量调试后,我意识到在拍摄照片之前我无意中停止了拍摄会话。请仔细检查.running
的{{1}}属性是否为AVCaptureSession
。