[英]setPreferredInput WithBlueTooth not working
我正在嘗試將藍牙設備設置為audioSession中的preferredinput。
這是我的代碼:
if(speaker)
{
NSLog(@"Audio use speaker");
CGFloat set = 5.0f;
AudioQueueSetParameter(audioQueue, kAudioQueueParam_Volume, set);
[sessionInstance overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
}else{
NSLog(@"QCAudio use headset");
NSError *audioError = nil;
BOOL hasAvaliableBuleTooth = NO;
NSArray* b_routePort = @[AVAudioSessionPortBluetoothHFP];
NSArray* portDescArr = [[AVAudioSession sharedInstance] availableInputs];
AVAudioSessionPortDescription* desPortDesc;
for (AVAudioSessionPortDescription* portDesc in portDescArr){
if ([b_routePort containsObject:portDesc.portType])
{
desPortDesc = portDesc;
hasAvaliableBuleTooth = YES;
}
}
if (hasAvaliableBuleTooth == YES) {
NSLog(@"1111111111 avsession desportDesc = %@",desPortDesc);
BOOL ret =[[AVAudioSession sharedInstance] setPreferredInput:desPortDesc error:&audioError];
NSLog(@"ret = %d current route = %@",ret, [[AVAudioSession sharedInstance] currentRoute]);
}else{
NSLog(@"222222222222 avsession");
CGFloat set = 1.0f;
AudioQueueSetParameter(audioQueue, kAudioQueueParam_Volume, set);
[sessionInstance overrideOutputAudioPort:AVAudioSessionPortOverrideNone
error:&error];
}
}
我有這個跡象:
2019-01-11 17:59:51.400283 + 0800 yichaoyun [4196:1228652] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields:端口h.ear(MDR-EX750BT)的未知選定數據源(類型:BluetoothHFP)
2019-01-11 17:59:51.400381 + 0800 yichaoyun [4196:1228652] 1111111111 avsession desportDesc =
2019-01-11 17:59:51.410321 + 0800 yichaoyun [4196:1228652] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields:端口h.ear(MDR-EX750BT)的未知選定數據源(類型:BluetoothHFP)
2019-01-11 17:59:51.410357 + 0800 yichaoyun [4196:1228652] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields:端口h.ear(MDR-EX750BT)的未知選定數據源(類型:BluetoothHFP)
2019-01-11 17:59:51.410447 + 0800 yichaoyun [4196:1228652] ret = 1當前路線=“);輸出=(”“)>
它表明連接藍牙設備是成功的,但是我只能聽到一些聲音,然后變成靜音。是否只有一個面臨相同問題的人,我該如何解決?
我終於找到了正確的答案。 應使用AVAudioSession
進行收集和記錄,這一點非常重要。
然后像這樣設置setCategory
:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&error];
設置preferredinput:
[[AVAudioSession sharedInstance] setPreferredInput:_bluetoothPort error:nil];
當您獲得這樣的當前輸入時:
inputs = (
"< AVAudioSessionPortDescription: 0x28185bf00, type = MicrophoneBuiltIn; name = iPhone \U9ea6\U514b\U98ce; UID = Built-In Microphone; selectedDataSource = \U524d >"
);
outputs = (
"< AVAudioSessionPortDescription: 0x28185bfb0, type = BluetoothA2DPOutput; name = h.ear (MDR-EX750BT); UID = 04:5D:4B:4A:4F:31-tacl; selectedDataSource = (null) >"
)>.
有用! 但是我仍然不明白為什么蘋果的輸入顯示首選輸入是``iPhone MicrophoneBuiltIn''而``藍牙耳機''有效,這是一個錯誤嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.