我正在录制视频,使用 AVFoundation 和 Swift 3 创建自定义相机。现在我想添加功能以在单击按钮时在视频录制期间静音/取消静音音频。我该如何实现?
最佳答案
我希望你使用 AVCaptureMovieFileOutput
从 AVFoundation
录制你的视频
没有直接的方法,但是如果你仔细阅读文档你可以看到
AVCaptureMovieFileOutput
是AVCaptureOutput
的子类- 您可以通过
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/