带有 AVAudioSessionCategoryPlayAndRecord 会话类别的蓝牙输出不起作用
任何人都知道为什么我无法在 iPad (iOS 5) 上的 AVAudioSessionCategoryPlayAndRecord 类别下获得蓝牙输出。
下面是我用来设置 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;
}
Anyone have any idea why I can't get bluetooth output to work on an iPad (iOS 5) under the AVAudioSessionCategoryPlayAndRecord category.
Below is the code I'm using to setup the AVAudioSessionCategoryPlayAndRecord category and enable bluetooth. If I switch the category to AVAudioSessionCategoryPlayback, bluetooth output works just fine to a variety of headsets and headphones. As soon as I switch to PlayAndRecord, no bluetooth output.
What am I doing wrong?
Suggestions, hypotheses appreciated. Thanks.
- (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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论