Playing Video (with audio; from asset) and recording video and audio (from front camera)?

Hi,

I do not know if is this possible, but I have problem to achieve this.

I have UIView (VideoView) who has AVPlayerLayer, and plays some video from assets, and have own audio.

Over this view, have another (smaller) UIView (CameraView) who have:
  • AVCaptureVideoPreviewLayer (show front camera)

  • AVCaptureSession

  • AVCaptureDevice

  • AVAudioSession

to show preview of user front camera and record audio & video from self.

And run in same time. Similar to FaceTime Call.

AVAudioSession in CameraView is set up something like this:
Code Block swift
let audioSession = AVAudioSession.sharedInstance()
      do {
        if #available(iOS 11.0, *) {
          try audioSession.setCategory(.playAndRecord, mode: .spokenAudio, policy: AVAudioSession.RouteSharingPolicy.default, options: [.duckOthers])
        } else {
          try audioSession.setCategory(.playAndRecord, mode: .spokenAudio)
        }
        try audioSession.setActive(true)
      } catch let error {
        print("Audio setup error", #file, #function, #line, error.localizedDescription)
      }


But still, I have some kind of echo in recorded video (recorded by CameraView) from playing video (VideoView).

I already try to save audio separately but problem is the same.

This is my first AV* app, and I do not have so much experience with audio / video at all.

Could someone point me where is my errors or point in right direction...

Thanks,
Milan






Playing Video (with audio; from asset) and recording video and audio (from front camera)?
 
 
Q