gpt4 book ai didi

iOS:如何检查扬声器是否打开

转载 作者:搜寻专家 更新时间:2023-11-01 06:58:52 25 4
gpt4 key购买 nike

我使用了 AVAudioSessionoverrideOutputAudioPort 方法在 iOS 的扬声器中播放声音。 overrideOutputAudioPort

我们如何检查输出音频是否被覆盖为扬声器,即声音是否由扬声器播放?

最佳答案

您可以使用 currentRoute 检查它,请考虑以下代码:

let currentRoute = AVAudioSession.sharedInstance().currentRoute

for output in currentRoute.outputs {

switch output.portType {

case AVAudioSessionPortBuiltInSpeaker:
print("Speaker is on.")
default:
break
}
}

您可以引用 Apple Doc 了解更多信息。

原始帖子是 here 。但它带有 if 检查,但根据我的说法,switch 更适合使用。

并且您可以检测 apple doc 中提到的其他输出。

关于iOS:如何检查扬声器是否打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51759492/

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