通过蓝牙连接的扬声器播放 [英] Playback through a bluetooth connected speaker

查看:99
本文介绍了通过蓝牙连接的扬声器播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我使用的是播放和录制"类别:

In my app I am using the play and record category aka:

UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
CheckError( AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
                                     sizeof (sessionCategory),
                                     &sessionCategory), "Couldn't set audio category");    

在应用程序中,任何播放的音频最初都会通过接收器输出,直到我设置了以下内容为止:

In the app any audio that plays would initially output through the receiver until I set this:

UInt32 doChangeDefaultRoute = 1;        
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute);  

但是,我真正想要的是通过连接的蓝牙扬声器输出音频.例如,我有一个通过蓝牙与之连接的扬声器.我可以使用本地音乐应用程序通过它播放音乐.但是,在我的应用中,使用playandrecord类别时,它只能在设备上播放.我已经尝试过:

What I actually want however is for audio to output through a connected bluetooth speaker. For example I have a speaker that I connect with via bluetooth. I am able to play music through it with the native music app. However in my app when using the playandrecord category it only plays on the device. I have tried:

UInt32 allowBluetoothInput = 1;
OSStatus stat = AudioSessionSetProperty (
                                         kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
                                         sizeof (allowBluetoothInput),
                                         &allowBluetoothInput
                                         );

以及:

CFStringRef audioRouteOverride = kAudioSessionOutputRoute_BluetoothHFP;

OSStatus s = AudioSessionSetProperty (kAudioSessionProperty_OutputDestination,
                                      sizeof(audioRouteOverride),&audioRouteOverride);

没有运气.似乎这应该是一个简单的属性集,但Idk.有什么想法吗?

No luck. It seems as though this should be an easy property set but Idk. Any ideas?

推荐答案

因此,首先,您需要知道它是哪种蓝牙设备.是 BluetoothHFP (输入和输出), BluetoothA2DP (仅输出)还是 BluetoothLE (仅输出).如果仅输出设备,则将无法连接和路由 kAudioSessionCategory_PlayAndRecord 类别中的音频.您可以尝试将类别设置为 kAudioSessionCategory_PlayBack ,看看是否可行.

So, first you need to know what kind of bluetooth device it is. Whether it is BluetoothHFP(input & output), BluetoothA2DP(output only) or BluetoothLE (output only). If the device is output only, you won't be able to connect and route the audio in kAudioSessionCategory_PlayAndRecord category. You could try setting the category to kAudioSessionCategory_PlayBack and see if this works.

我一周前遇到了同样的问题.我的应用程序需要输入和输出,因此我必须将类别设置为 kAudioSessionCategory_PlayAndRecord .因此,我计划根据不同类型的蓝牙设备来更改会话类别.

I encountered the same problem a week ago. My application requires both input and output so I must set the category to kAudioSessionCategory_PlayAndRecord. So I plan to change the session category based on different type of bluetooth device.

这篇关于通过蓝牙连接的扬声器播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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