iOS Swift AVAudioSession – 明确切换到蓝牙路由

huangapple go评论72阅读模式
英文:

iOS Swift AVAudioSession - Changing Route to bluetooth explicitly

问题

我需要满足一项需求,我需要展示已连接的蓝牙设备并在那里播放音频,目前我已经完成了这一点。但是,假设我想从蓝牙切换到手机扬声器,然后在一段时间后再次连接到蓝牙,我能做到吗?如果不能,那么我应该采取什么措施来实现这一目标。谢谢。

英文:

So I am in need of a requirement where I have to show, connected bluetooth device and play audio there, which currently I have done already. But say I want to switch from my bluetooth to Phones speaker, and connect back to bluetooth again after some point, can I do this? if not what would be my option to achieve this.
Thanks

答案1

得分: 1

要切换路由,您需要更改会话的选项。例如,要从蓝牙切换到内置扬声器,您需要删除.allowBluetoothA2DP选项,并可能添加.defaultToSpeaker选项。要切换回A2DP蓝牙,您可以反转选项。(如果您需要HFP而不是A2DP,请使用.allowBluetooth而不是.allowBluetoothA2DP。)

英文:

To switch routes, you will change the session's options. For example, to switch from Bluetooth to the internal speaker, you'll want to remove the .allowBluetoothA2DP option and likely add the .defaultToSpeaker option. To move back to A2DP Bluetooth, you would reverse the options. (If you need HFP rather than A2DP, use .allowBluetooth rather than .allowBluetoothA2DP.)

huangapple
  • 本文由 发表于 2023年7月3日 03:46:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76600527.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定