带有 AVAudioSessionCategoryPlayAndRecord 会话类别的蓝牙输出不起作用

发布于 2025-01-02 11:08:27 字数 1572 浏览 2 评论 0原文

任何人都知道为什么我无法在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文