- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在我的 iPhone 应用程序中,我需要启用扬声器和蓝牙。
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,
sizeof (audioRouteOverride), &audioRouteOverride);
UInt32 allowBluetoothInput = 1;
AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
sizeof (allowBluetoothInput),
&allowBluetoothInput
);
但它不能协同工作。我的意思是,如果蓝牙打开,我会听到来自 BT 耳机的声音,如果它关闭,我听到的声音不是来自扬声器。我该如何解决这个问题?
最佳答案
您是否尝试过为扬声器使用 changeDefaultRoute
而不是 audioRouteOverride
?
UInt32 doChangeDefaultRoute = 1;
AudioSessionSetProperty(
kAudioSessionProperty_OverrideCategoryDefaultToSpeaker
, sizeof(doChangeDefaultRoute)
, &doChangeDefaultRoute);
这解决了输出到扬声器而不是接收器的问题,但我无法测试蓝牙输入端(没有蓝牙设备!)。它可能不因为我可以收集到OverrideCategoryEnableBluetoothInput
实际上控制输入和输出。
Apple 是这样说的:
This property affects the kAudioSessionCategory_PlayAndRecord category as follows: If the audio input to the device is coming from a Bluetooth headset, setting this property to TRUE results in audio output also going to the Bluetooth headset. (Audio Session Services Reference)
一般来说,Apple 不希望应用程序以可能违反用户直觉的方式操纵路由。这个想法是路由应该是用户觉得他们可以控制的东西。
关于iphone - iPhone 上的 AudioSessionProperty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16189685/
在我的 iPhone 应用程序中,我需要启用扬声器和蓝牙。 [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPl
我是一名优秀的程序员,十分优秀!