我制作了一个成功的视频录制节目,但它没有音频?我该怎么做才能解决这个问题?我已经在我的设置中正确设置了音频权限info.plist
.我正在使用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") } } }
我已经尝试过这里发布的解决方案,但它所做的一切都搞砸了我已经使用相机的工作.任何指导表示赞赏!
简单的步骤,实现你想要的:
获取视频捕获设备(AVMediaTypeVideo)
获取音频捕获设备(AVMediaTypeAudio)
创建视频输入(带视频设备的AVCaptureDeviceInput)
创建音频输入(带音频设备的AVCaptureDeviceInput)
通过beginConfiguration()配置捕获会话(AVCaptureSession)
添加输入以通过addInput()捕获会话
通过commitConfiguration()提交配置