iOS:使用蓝牙音频输出(kAudioSessionProperty_OverrideCategoryEnableBluetoothInput)AudioSession

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

>蓝牙HFP音频输出(kAudioSessionOutputRoute_BluetoothHFP)仅在AudioSession设置kAudioSessionCategory_PlayAndRecord且您覆盖以下属性时才可用:kAudioSessionProperty_OverrideCategoryEnableBluetoothInput.这是真的?如果没有,我将如何通过mediaplayback会话作为示例路由到kAudioSessionOutputRoute_BluetoothHFP路由.
>类别为kAudioSessionCategory_PlayAndRecord时,无法在后台模式下输出音频.因此,如果我在后台,我无法通过蓝牙HFP路线播放声音.这是真的?如果app在后台,有没有办法通过蓝牙HFP协议发送音频?
>如果有可用的A2DP设备,我的音频路由将始终自动切换到kAudioSessionOutputRoute_BluetoothA2DP路由.如何防止此路线更改?另外,我如何指定我想要的输出路线.使用iOS5,可以通过kAudioSessionProperty_AudioRouteDescription标志查询所有这些路由目的地,但我不知道如何设置它,因为我想拥有它.是否有可能实现这一目标?

我希望你们中的一些人可以帮助我解决这些问题.这对我对CoreAudio的整体理解,特别是AudioSession框架,真的有帮助.

解决方法

AudioSession是一项棘手的业务.

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设置,以便从蓝牙耳机中播放音频. EnableBluetoothInput根据this影响输入和输出.另外请记住,由于蓝牙输入设备的限制,音频将以8000 Hz的频率播放.对于支持A2DP的已连接设备,您可以将其保留在音频会话kAudioSessionCategorymediaplayback中,它将以44100 Hz采样率播放.

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播放音频.查看更多here.

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.这可能不受您的控制,音频会话将使用它认为对用户直观的内容.如果他们刚刚连接了A2DP设备并且您只输出音频,则将使用A2DP设备.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...