ios - swift 3 : How to mute/unmute microphone during video recording using AVFoundation

标签 ios iphone swift xcode

我正在录制视频,使用 AVFoundation 和 Swift 3 创建自定义相机。现在我想添加功能以在单击按钮时在视频录制期间静音/取消静音音频。我该如何实现?

最佳答案

我希望你使用 AVCaptureMovieFileOutputAVFoundation 录制你的视频

没有直接的方法,但是如果你仔细阅读文档你可以看到

  • AVCaptureMovieFileOutputAVCaptureOutput 的子类
  • 您可以通过 func connection(withMediaType mediaType: String!) -> AVCaptureConnection 单独从您的 AVCaptureMovieFileOutput 获得音频连接! 通过将媒体类型作为音频传递
  • 单独获得auido连接后,将其禁用即可

swift 示例

let movieFileOutput : AVCaptureMovieFileOutput
// your code to initialize output
var audioConnection :AVCaptureConnection? = movieFileOutput.connection(withMediaType:AVMediaTypeAudio)
if let connection = audioConnection {
    connection.isEnabled = false;
}

表单文档

对于 AVCaptureConnection 属性 enabled

The value of this property is a BOOL that determines whether the receiver's output should consume data from its connected inputPorts when a session is running. Clients can set this property to stop the flow of data to a given output during capture. The default value is YES.

关于ios - swift 3 : How to mute/unmute microphone during video recording using AVFoundation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41608113/

相关文章:

iphone - 具有淡入/淡出效果的 UIScrollView

swift - 没有待激活的快照。 SDK 名称 : app_measurement

ios - RestKit 在 PUT 请求时抛出 NSInternalInconsistencyException

ios - XCTest - 等待谓词失败

ios - 尝试更改文本值时连接的 UILabel 错误 EXC_BAD_EXCEPTION

ios - 查看核心数据iOS中的所有记录

ios - 推送通知在 Live iOS 应用程序上停止

ios - 使用 AVAudioPlayer 从 URL 播放音频歌曲?

ios - 使用另一个 FIRApp 的 FIRMessaging

具有支付处理功能的 iOS 刷卡器