英文:
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
.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论