简体   繁体   中英

parallel working on video recording and phone call functionalities in iOS swift3

I have two methods like phone call function and camera video recording functions. These two functions working fine individually. But when I use these two functions at a time camera function not working. How can I call these two methods at a time for proper working in ios swift. I found the error is that audio enabling to both functions at a time. thats why it is crashing. May I disable the audio of video recording upto phone call completed?

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")
            }

        }
    }

}

I hope this will help you.

As per your error -11818 it's happen means AVErrorSessionWasInterrupted like other apps interrupted your video decoding.For fix this problem you need to enable AVAudioSessionCategoryOptions.MixWithOthers. For more Info use this link:- enter link description here

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM