我已将
MPVolumeView
集成到我的视图中,并且它按预期正确响应硬件音量变化。但是,一旦我使用 AVAudioEngine
捕获麦克风音频并使用 AudioUnit
进行解码启动音频流,MPVolumeView 就不再反映使用硬件音量按钮所做的更改。此外,即使我使用 MPVolumeView 上的滑块调整音量,它也不会改变系统音量。还有其他人遇到过这个问题吗?一旦流开始,什么可能导致 MPVolumeView 停止响应硬件音量变化?
对于
AVAudioSession.Mode
,我使用 default
设置,因为使用 .voiceChat
可以永久阻止 MPVolumeView
因设备音量变化而更新。
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(.playAndRecord, options: [.allowBluetooth])
try session.setActive(true)
} catch {
print(error.localizedDescription)
}
使用
kAudioUnitSubType_VoiceProcessingIO
代替 AudioComponentDescription
是问题所在。