【问题标题】:Can a AVCaptureFileOutputRecordingDelegate be added to a subclass UIView?可以将 AVCaptureFileOutputRecordingDelegate 添加到子类 UIView 中吗?
【发布时间】:2016-05-31 22:33:54
【问题描述】:

我在自定义 UIView 中创建捕获会话时遇到问题。我这样设置委托

class Camera: UIView, AVCaptureFileOutputRecordingDelegate, AVAudioRecorderDelegate {
}

然后我设置好一切并像这样设置委托

self.recordingDelegate? = self

    captureSession.sessionPreset = AVCaptureSessionPresetHigh
    let devices = AVCaptureDevice.devices()
    for device in devices {
        if (device.hasMediaType(AVMediaTypeVideo)) {
            if(device.position == AVCaptureDevicePosition.Back) {
                captureDevice = device as? AVCaptureDevice
                if captureDevice != nil {
                    beginSession()
                }
            }
        }
    }

一切顺利。但是,在 beginSession 函数中:

    func beginSession() {
        let err : NSError? = nil
        do {
            self.captureSession.addInput(try AVCaptureDeviceInput(device: self.captureDevice!))
        }
        catch {
            print("dang")
        }
        if err != nil {
            print("error: \(err?.localizedDescription)")
        }

...

当我尝试添加捕获设备输入时抛出了问题,因为它没有被添加,我不知道为什么。

我目前使用的所有代码在我将它放在 UIViewController 中之前都可以正常工作,但是当我将它切换到 UIView 的子类时它停止工作。如果需要更多代码,任何帮助将不胜感激,请告诉我谢谢!

【问题讨论】:

  • 您可以打印捕获的异常并编辑您的帖子吗?
  • 什么?这段代码我没有收到任何错误
  • 当您说“catch is throws”时,您的意思是您在控制台中看到了“dang”吗?如果是,则抛出异常

标签: ios swift avcapturesession avcapturedevice


【解决方案1】:

我发现我使用的 iOS 设备由于某种原因没有启用相机,因为无法添加输入,导致预览层无法捕获任何数据

【讨论】:

    猜你喜欢
    • 2014-08-09
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 2023-03-04
    • 1970-01-01
    • 2019-08-30
    相关资源
    最近更新 更多