ios - 录制视频时的音频音量
<p><p>所以经过大量搜索后,我找到了允许在录制视频的同时播放背景音频的代码块。
我在下面粘贴了上述代码块。</p>
<pre><code>fileprivate func setBackgroundAudioPreference() {
guard allowBackgroundAudio == true else {
return
}
guard audioEnabled == true else {
return
}
do{
if #available(iOS 10.0, *) {
try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: [.mixWithOthers, .allowBluetooth, .allowAirPlay, .allowBluetoothA2DP])
} else {
let options: = [.mixWithOthers, .allowBluetooth]
let category = AVAudioSession.Category.playAndRecord
let selector = NSSelectorFromString("setCategory:withOptions:error:")
AVAudioSession.sharedInstance().perform(selector, with: category, with: options)
}
try AVAudioSession.sharedInstance().setActive(true)
session.automaticallyConfiguresApplicationAudioSession = false
}
catch {
print(": Failed to set background audio preference")
}
}
</code></pre>
<p>但是,我有一个小问题。由于某种原因,当相机加载背景时,音频音量会降低。当我用 instagram 录制视频时,音频不会减少,它仍然会录制有没有什么办法可以改变我当前的代码块,在用视频重新编码时不降低音量?</p>
<p>我阅读了文档,显然 .duckOthers 选项应该是减少音量的唯一选项。但是这个也可以</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>好的,我在深入研究一些文档后找到了答案。</p>
<p>下面发布的更新代码。您所要做的就是设置 .defaultToSpeaker 选项</p>
<pre><code>fileprivate func setBackgroundAudioPreference() {
guard allowBackgroundAudio == true else {
return
}
guard audioEnabled == true else {
return
}
do{
if #available(iOS 10.0, *) {
try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: [.mixWithOthers, .allowBluetooth, .allowAirPlay, .allowBluetoothA2DP,.defaultToSpeaker])
} else {
let options: = [.mixWithOthers, .allowBluetooth]
let category = AVAudioSession.Category.playAndRecord
let selector = NSSelectorFromString("setCategory:withOptions:error:")
AVAudioSession.sharedInstance().perform(selector, with: category, with: options)
}
try AVAudioSession.sharedInstance().setActive(true)
session.automaticallyConfiguresApplicationAudioSession = false
}
catch {
print(": Failed to set background audio preference")
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 录制视频时的音频音量,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/54578598/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/54578598/
</a>
</p>
页:
[1]