任何人都知道为什么我无法在AVAudioSessionCategoryPlayAndRecord类别的iPad(iOS 5)上使用蓝牙输出。
下面是我用来设置AVAudioSessionCategoryPlayAndRecord类别并启用蓝牙的代码。如果我将类别切换到AVAudioSessionCategoryPlayback,蓝牙输出可以很好地适用于各种耳机和耳机。一旦我切换到PlayAndRecord,就没有蓝牙输出。
我做错了什么?
建议,假设赞赏。感谢。
- (BOOL) setAudioSessionCategoryToPlayAndRecordWithBluetoothEnabled {
AudioSessionInitialize(NULL,NULL,NULL,NULL);
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err;
if (![audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&err])
{
fprintf(stderr,"oh no...");
return NO;
}
// make active
[audioSession setActive: YES error: nil];
// allow bluetooth
UInt32 allowBluetoothInput = 1;
OSStatus stat = AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
sizeof (allowBluetoothInput),
&allowBluetoothInput
);
if (stat) {
fprintf(stderr,"not good...");
return FALSE;
}
// check for bluetooth route
// (NB: this never works if category is AVAudioSessionCategoryPlayAndRecord)
UInt32 size = sizeof(CFStringRef);
CFStringRef route;
stat = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &route);
NSLog(@"route = %@", route);
return TRUE;
}