gpt4 book ai didi

ios - 在 iOS swift3 中并行处理视频录制和通话功能

转载 作者:行者123 更新时间:2023-11-30 11:03:17 25 4
gpt4 key购买 nike

我有两种方法,比如打电话功能和摄像头录像功能。这两个功能单独工作得很好。但是当我同时使用这两个功能时,相机功能不起作用。我如何一次调用这两个方法才能在 ios swift 中正常工作。我发现错误是音频同时启用这两种功能。这就是它崩溃的原因。我可以在通话结束前禁用视频录制的音频吗?

func makeCall(phoneNumber: String) {
let formattedNumber = phoneNumber.components(separatedBy:
NSCharacterSet.decimalDigits.inverted).joined(separator: "")

let phoneUrl = "tel://\(formattedNumber)"
let url:NSURL = NSURL(string: phoneUrl)!

if #available(iOS 10, *) {
UIApplication.shared.open(url as URL, options: [:], completionHandler:
nil)


} else {
UIApplication.shared.openURL(url as URL)


}
}

func videoMethodNew()

{

let devices = AVCaptureDevice.devices(for: AVMediaType.video)


guard AVCaptureDevice.default(for: .audio) != nil else { return }

for device in devices {
if (device as AnyObject).position == AVCaptureDevice.Position.back{


do{

let input = try AVCaptureDeviceInput(device: device )

if captureSession.canAddInput(input){

captureSession.addInput(input)
sessionOutput.outputSettings = [AVVideoCodecKey : AVVideoCodecJPEG]

if captureSession.canAddOutput(sessionOutput){

captureSession.addOutput(sessionOutput)

previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
previewLayer.connection?.videoOrientation = AVCaptureVideoOrientation.portrait
cameraView.layer.addSublayer(previewLayer)

previewLayer.position = CGPoint(x: self.cameraView.frame.width / 2, y: self.cameraView.frame.height / 2)
previewLayer.bounds = cameraView.frame


}

captureSession.addOutput(movieOutput)

captureSession.startRunning()

self.handleCaptureSession()

}

}
catch{

print("Error")
}

}
}

}

最佳答案

希望这对您有帮助。

根据您的错误-11818,发生这种情况意味着 AVErrorSessionWasInterrupted 像其他应用程序一样中断了您的视频解码。要解决此问题,您需要启用 AVAudioSessionCategoryOptions.MixWithOthers。欲了解更多信息,请使用此链接:- enter link description here

谢谢

关于ios - 在 iOS swift3 中并行处理视频录制和通话功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53040117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com