iOS:使用蓝牙音频输出 (kAudioSessionProperty_OverrideCategoryEnableBluetoothInput) AudioSession [英] iOS: Using Bluetooth audio output (kAudioSessionProperty_OverrideCategoryEnableBluetoothInput) AudioSession

查看:33
本文介绍了iOS:使用蓝牙音频输出 (kAudioSessionProperty_OverrideCategoryEnableBluetoothInput) AudioSession的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 CoreAudio AudioSession 框架有几个与几个蓝牙任务相关的问题,我希望有人可以帮助我解决这些问题,或者至少可以确认我的最新发现.用例是一个导航应用程序,想要连接支持 HFP 和 A2DP 的蓝牙无线电.我已经阅读了整个 AudioSession 编程指南,但我仍然有一些未解决的问题,尤其是通过蓝牙使用音频输出.

I have several questions to the CoreAudio AudioSession framework related to several Bluetooth tasks and I hope someone can help me with these issues or at least can confirm my latest findings. The usecase is a navigation app that wants to connect with a bluetooth enabled radio which supports both, HFP and A2DP. I have read the whole AudioSession Programming Guidelines but I have still some open issues especially using audio output through Bluetooth.

  1. 蓝牙 HFP 音频输出 (kAudioSessionOutputRoute_BluetoothHFP) 仅在设置了 AudioSession kAudioSessionCategory_PlayAndRecord 并且您覆盖以下属性的情况下可用:kAudioSessionProperty_OverrideCategoryEnableBluetoothInput.这是真的?如果没有,我如何将 MediaPlayback 会话作为示例路由到 kAudioSessionOutputRoute_BluetoothHFP 路由.

  1. Bluetooth HFP audio output (kAudioSessionOutputRoute_BluetoothHFP) is only possible in case of AudioSession kAudioSessionCategory_PlayAndRecord is set and you are overriding the following property: kAudioSessionProperty_OverrideCategoryEnableBluetoothInput. Is this true? If not, how I can route as an example with the MediaPlayback session to kAudioSessionOutputRoute_BluetoothHFP route.

背景模式下的音频输出无法使用 kAudioSessionCategory_PlayAndRecord 类别.因此,如果我在后台,则无法通过蓝牙 HFP 路由播放声音.这是真的?如果应用程序在后台,有没有办法通过蓝牙 HFP 协议发送音频?

Audio output in background mode is not possible with the category kAudioSessionCategory_PlayAndRecord. Therefore I can not play sound through an bluetooth HFP route if I am in background. Is this true? Is there a way how to send audio through the Bluetooth HFP protocol if app is in the background?

如果有可用的 A2DP 设备,我的音频路由将始终自动切换到 kAudioSessionOutputRoute_BluetoothA2DP 路由.如何防止此路线更改?此外,我如何指定我目前想要的输出路线.使用 iOS5 可以通过 kAudioSessionProperty_AudioRouteDescription 标志查询所有这些路由目的地,但我不知道如何设置它,因为我想要它.是否有可能实现这一目标?

If there is an A2DP enabled device available my audio route will always switch automatically to the kAudioSessionOutputRoute_BluetoothA2DP route. How can I prevent this route change? In addition how can I specify the output route I wanna have at the moment. With iOS5 it is possible to query all those route destination through the kAudioSessionProperty_AudioRouteDescription flag, but I have no idea how I can set it as I wanna have it. Is it somehow possible to achieve this?

我希望你们中的一些人能帮助我解决这些问题.这真的会帮助我全面了解 CoreAudio,尤其是 AudioSession 框架.

I hope some of you can help me with these questions. It would really help me with my overall understanding of the CoreAudio, especially the AudioSession framework.

推荐答案

AudioSession 是一件棘手的事情.

AudioSession is tricky business.

1.Bluetooth HFP 音频输出 (kAudioSessionOutputRoute_BluetoothHFP) 仅在设置了 AudioSession kAudioSessionCategory_PlayAndRecord 并且您覆盖以下属性时才可用:kAudioSessionProperty_OverrideCategoryEnableBluetoothInput.这是真的?如果没有,我如何将 MediaPlayback 会话作为示例路由到 kAudioSessionOutputRoute_BluetoothHFP 路由.

1.Bluetooth HFP audio output (kAudioSessionOutputRoute_BluetoothHFP) is only possible in case of AudioSession kAudioSessionCategory_PlayAndRecord is set and you are overriding the following property: kAudioSessionProperty_OverrideCategoryEnableBluetoothInput. Is this true? If not, how I can route as an example with the MediaPlayback session to kAudioSessionOutputRoute_BluetoothHFP route.

如果您连接了蓝牙耳机,那么确实如此.您将需要 kAudioSessionCategory_PlayAndRecord 音频会话集和 kAudioSessionProperty_OverrideCategoryEnableBluetoothInput 集才能从蓝牙耳机播放音频.根据this,EnableBluetoothInput 会影响输入和输出.另请记住,由于蓝牙输入设备的限制,音频将以 8000 Hz 播放.对于支持 A2DP 的已连接设备,您可以将其保留在音频会话 kAudioSessionCategoryMediaPlayback 中,它将以 44100 Hz 采样率播放.

If you have a Bluetooth headset connected, then it is true. You will need both kAudioSessionCategory_PlayAndRecord audio session set and kAudioSessionProperty_OverrideCategoryEnableBluetoothInput set to have audio play out of a Bluetooth headset. EnableBluetoothInput affects both input and output according to this. Also remember, the audio will play at 8000 Hz due to the limitation of bluetooth input devices. For a device that is connected that supports A2DP, you can leave it at audio session kAudioSessionCategoryMediaPlayback and it will play at 44100 Hz sample rate.

2. 后台模式下的音频输出无法使用 kAudioSessionCategory_PlayAndRecord 类别.因此,如果我在后台,则无法通过蓝牙 HFP 路由播放声音.这是真的?如果应用程序在后台,有没有办法通过蓝牙 HFP 协议发送音频?

2.Audio output in background mode is not possible with the category kAudioSessionCategory_PlayAndRecord. Therefore I can not play sound through an bluetooth HFP route if I am in background. Is this true? Is there a way how to send audio through the Bluetooth HFP protocol if app is in the background?

只要您在应用 plist 中设置了后台音频模式键,就可以在后台通过蓝牙 HFP 播放音频.在此处查看更多信息.

Playing audio through the bluetooth HFP is possible in the background as long as you have set the background audio mode key in your app plist. See more here.

3.如果有可用的 A2DP 设备,我的音频路由将始终自动切换到 kAudioSessionOutputRoute_BluetoothA2DP 路由.如何防止此路线更改?此外,我如何指定我目前想要的输出路线.使用 iOS5 可以通过 kAudioSessionProperty_AudioRouteDescription 标志查询所有这些路由目的地,但我不知道如何设置它,因为我想要它.是否有可能实现这一目标?

3.If there is an A2DP enabled device available my audio route will always switch automatically to the kAudioSessionOutputRoute_BluetoothA2DP route. How can I prevent this route change? In addition how can I specify the output route I wanna have at the moment. With iOS5 it is possible to query all those route destination through the kAudioSessionProperty_AudioRouteDescription flag, but I have no idea how I can set it as I wanna have it. Is it somehow possible to achieve this?

您希望音频去哪里?您可以尝试将音频会话设置为 PlayAndRecord 以防止其进入 A2DP.不过,这可能超出您的控制,Audio Session 将使用它认为对用户来说直观的内容.如果他们只是连接了 A2DP 设备,而您只是输出音频,则将使用 A2DP 设备.

Where do you want the audio to go instead? You can try to set the audio session to PlayAndRecord to keep it from going to A2DP. This may be out of your control though, Audio Session will use what it deems to be intuitive to the user. If they just connected an A2DP device and you are only outputting audio, the A2DP device will be used.

这篇关于iOS:使用蓝牙音频输出 (kAudioSessionProperty_OverrideCategoryEnableBluetoothInput) AudioSession的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆