ios - 是否可以将 AVCaptureFileOutputRecordingDelegate 添加到子类 UIView 中?

标签 ios swift avcapturesession avcapturedevice

我在自定义 UIView 中创建捕获 session 时遇到问题。我这样设置委托(delegate)

class Camera: UIView, AVCaptureFileOutputRecordingDelegate, AVAudioRecorderDelegate {
}

然后我设置所有内容并像这样设置委托(delegate)

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 的子类时,它停止工作。如果需要更多代码,请告诉我,任何帮助将不胜感激!

最佳答案

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

关于ios - 是否可以将 AVCaptureFileOutputRecordingDelegate 添加到子类 UIView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37556728/

相关文章:

ios - 如何按步数获取CMPedometer数据?

ios - ViewController 关闭 swift ios

ios - 根据标签获取按钮标题 - Objective C

ios - 使用自动布局使 UIView 和内容扩展以填充 UIToolbar 中的可用水平空间

ios - AVCaptureSession的设置与iPhone相机内置的设置相同

ios - 在iOS上捕获60fps帧以减少运动模糊

ios - 将 CMSampleBuffer 转换为 UIImage

objective-c - 是否可以从iOS应用程序中的麦克风获得声压?

ios - 搜索 firebase 数据 : iOS, Swift

ios - Firebase Google SignIn 每次都询问权限