无法在Swift Playgrounds上捕获视频数据,captureOutput AVCaptureVideoDataOutputSampleBufferDelegate委托方法未调用

无法在Swift Playgrounds上捕获视频数据,captureOutput AVCaptureVideoDataOutputSampleBufferDelegate委托方法未调用,第1张

概述我想在Swift Playgrounds iPad应用程序上访问iPad的相机。我发现即使我的游乐场运行良好,它也不可能捕获视频数据。 captureOutput(_ captureOutput:AVCaptureOutput!,didOutputSampleBuffer sampleBuffer:CMSampleBuffer!,来自连接:AVCaptureConnection!),AVCaptu 我想在Swift Playgrounds iPad应用程序上访问iPad的相机。我发现即使我的游乐场运行良好,它也不可能捕获视频数据。

captureOutput(_ captureOutput:AVCaptureOutput!,dIDOutputSampleBuffer sampleBuffer:CMSampleBuffer!,来自连接:AVCaptureConnection!),AVCaptureVIDeoDataOutputSampleBufferDelegate协议的委托方法未被调用(可能是因为没有视频数据进入),而它在我的iOS中应用程序。

我的 *** 场上的视图应该显示FaceTime摄像机视图。为什么即使Apple explicitly says it’s allowed to do so也无法显示相机输出?此外,Playground应用程序会在我打开游乐场时立即询问相机权限,因此应该以某种方式允许它。

import UIKitimport CoreImageimport AVFoundationimport ImageIOimport PlaygroundSupportclass Visage: NSObject,AVCaptureVIDeoDataOutputSampleBufferDelegate {    var visageCameraview : UIVIEw = UIVIEw()    fileprivate var faceDetector : CIDetector?    fileprivate var vIDeoDataOutput : AVCaptureVIDeoDataOutput?    fileprivate var vIDeoDataOutputQueue : dispatchQueue?    fileprivate var cameraPrevIEwLayer : AVCaptureVIDeoPrevIEwLayer?    fileprivate var captureSession : AVCaptureSession = AVCaptureSession()    fileprivate let notificationCenter : NotificationCenter = NotificationCenter.default    overrIDe init() {        super.init()        self.capturesetup(AVCaptureDeviceposition.front)        var faceDetectorOptions : [String : AnyObject]?        faceDetectorOptions = [CIDetectorAccuracy : CIDetectorAccuracyHigh as AnyObject]        self.faceDetector = CIDetector(ofType: CIDetectorTypeFace,context: nil,options: faceDetectorOptions)    }    func beginFaceDetection() {        self.captureSession.startRunning()    }    func endFaceDetection() {        self.captureSession.stopRunning()    }    fileprivate func capturesetup (_ position : AVCaptureDeviceposition) {        var captureError : NSError?        var captureDevice : AVCaptureDevice!        for testedDevice in AVCaptureDevice.devices(withMediaType: AVMediaTypeVIDeo){            if ((testedDevice as AnyObject).position == position) {                captureDevice = testedDevice as! AVCaptureDevice            }        }        if (captureDevice == nil) {            captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVIDeo)        }        var deviceinput : AVCaptureDeviceinput?        do {            deviceinput = try AVCaptureDeviceinput(device: captureDevice)        } catch let error as NSError {            captureError = error            deviceinput = nil        }        captureSession.sessionPreset = AVCaptureSessionPresetHigh        if (captureError == nil) {            if (captureSession.canAddinput(deviceinput)) {                captureSession.addinput(deviceinput)            }            self.vIDeoDataOutput = AVCaptureVIDeoDataOutput()            self.vIDeoDataOutput!.vIDeoSettings = [kCVPixelBufferPixelFormatTypeKey as AnyHashable: Int(kCVPixelFormatType_32BGRA)]            self.vIDeoDataOutput!.alwaysdiscardsLateVIDeoFrames = true            self.vIDeoDataOutputQueue = dispatchQueue(label: "VIDeoDataOutputQueue",attributes: [])            self.vIDeoDataOutput!.setSampleBufferDelegate(self,queue: self.vIDeoDataOutputQueue!)            if (captureSession.canAddOutput(self.vIDeoDataOutput)) {                captureSession.addOutput(self.vIDeoDataOutput)            }        }        visageCameraview.frame = UIScreen.main.bounds        let prevIEwLayer = AVCaptureVIDeoPrevIEwLayer(session: captureSession)        prevIEwLayer?.frame = UIScreen.main.bounds        prevIEwLayer?.vIDeoGravity = AVLayerVIDeoGravityResizeAspectFill        visageCameraview.layer.addSublayer(prevIEwLayer!)    }    // NOT CALLED    func captureOutput(_ captureOutput: AVCaptureOutput!,dIDOutputSampleBuffer sampleBuffer: CMSampleBuffer!,from connection: AVCaptureConnection!) {                    print("delegate method called!")    }}class SmileVIEw: UIVIEw {    let smileVIEw = UIVIEw()    var smileRec: Visage!    overrIDe init(frame: CGRect) {        super.init(frame: frame)        self.addSubvIEw(smileVIEw)        self.translatesautoresizingMaskIntoConstraints = false        smileRec = Visage()        smileRec.beginFaceDetection()        let cameraview = smileRec.visageCameraview        self.addSubvIEw(cameraview)    }    required init?(coder aDecoder: NSCoder) {        fatalError("init(coder:) has not been implemented")    }}let frame = CGRect(x: 0,y: 0,wIDth: UIScreen.main.bounds.wIDth,height: UIScreen.main.bounds.height)let sVIEw = SmileVIEw(frame: frame)PlaygroundPage.current.liveVIEw = sVIEw
编辑:这应该是固定的:)

编辑:这被证实是Apple的一个错误。

我已经提交了一份错误报告,当新的官方信息出现时我会更新这个答案。

总结

以上是内存溢出为你收集整理的无法在Swift Playgrounds上捕获视频数据,captureOutput AVCaptureVideoDataOutputSampleBufferDelegate委托方法未调用全部内容,希望文章能够帮你解决无法在Swift Playgrounds上捕获视频数据,captureOutput AVCaptureVideoDataOutputSampleBufferDelegate委托方法未调用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1052193.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存