gpt4 book ai didi

ios - 如何为IOS视频应用选择底部麦克风?

转载 作者:行者123 更新时间:2023-11-30 12:30:39 25 4
gpt4 key购买 nike

我在网上找到了这个示例代码:https://developer.apple.com/library/content/samplecode/AVCam/Introduction/Intro.html

我正在尝试将 iPhone 上的输入麦克风从默认麦克风更改为底部麦克风。有谁有 Swift 中这方面的经验吗?我发现的唯一示例是在 Obj-C 中,并且在实现它们时导致了错误。我使用苹果的 AVCam 示例应用程序作为引用,音频部分包含在下面。

// Add audio input.
do {
let audioDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio)
let audioDeviceInput = try AVCaptureDeviceInput(device: audioDevice)

if session.canAddInput(audioDeviceInput) {
session.addInput(audioDeviceInput)
}
else {
print("Could not add audio device input to the session")
}
}
catch {
print("Could not create audio device input: \(error)")
}

最佳答案

您应该尝试使用以下方法设置 session 类别:

session.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.DefaultToSpeaker, error: nil)

这应该默认使用底部麦克风

关于ios - 如何为IOS视频应用选择底部麦克风?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43598128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com