如何在iOS迅速拨打电话的同时录制视频

时间:2018-11-08 04:54:37

标签: ios iphone swift

我正在做一个像SOS这样的项目。当用户单击SOS按钮时,我需要调用两种方法,即电话呼叫方法和摄像机视频录制。

这两个函数在我每次单独调用时都能正常工作。但是一次无法正常工作意味着可以打电话,但无法进行摄像机视频录制。我认为音频功能不支持这两种功能。打电话时如何使视频录制静音?

有人可以指导我解决这个问题吗?

func videoMethod() {
  let devices = AVCaptureDevice.devices(for: AVMediaType.video)
  guard AVCaptureDevice.default(for: .video) != 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.remo
            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")
      }
    }
  }
}


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

0 个答案:

没有答案