I made a successful video recording program, but it has no sound? What should I do to fix this? I have permissions correctly configured in my info.plist
. I am using AVCaptureFileOutputRecordingDelegate
.
override func viewWillAppear(_ animated: Bool) { let deviceDiscoverySession = AVCaptureDeviceDiscoverySession(deviceTypes: [AVCaptureDeviceType.builtInDuoCamera, AVCaptureDeviceType.builtInTelephotoCamera,AVCaptureDeviceType.builtInWideAngleCamera], mediaType: AVMediaTypeVideo, position: AVCaptureDevicePosition.back) for device in (deviceDiscoverySession?.devices)!{ if(device.position == AVCaptureDevicePosition.back){ do{ let input = try AVCaptureDeviceInput(device: device ) if captureSession.canAddInput(input){ captureSession.addInput(input) } // sessionOutput.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString) : NSNumber(value: kCVPixelFormatType_420YpCbCr8BiPlanarFullRange as UInt32)] sessionOutput.alwaysDiscardsLateVideoFrames = true if(captureSession.canAddOutput(sessionOutput) == true){ captureSession.addOutput(sessionOutput) let previewLayer: AVCaptureVideoPreviewLayer = { let preview = AVCaptureVideoPreviewLayer(session: self.captureSession) preview?.bounds = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height) preview?.position = CGPoint(x: self.view.bounds.midX, y: self.view.bounds.midY) preview?.videoGravity = AVLayerVideoGravityResize return preview! }() view.layer.insertSublayer(previewLayer, at: 0) output = AVCaptureMovieFileOutput() let maxDuration = CMTimeMakeWithSeconds(180, 30) output.maxRecordedDuration = maxDuration captureSession.addOutput(output) } captureSession.commitConfiguration() } catch{ print("Error") } } }
I tried the solution posted here , but all he did was spoil what I already worked with the camera. Any guidance appreciated!
source share