gpt4 book ai didi

ios - AVAudioPlayer 和 AVAudioSession 不会在 iPad(2 或其他)上播放蓝牙立体声

转载 作者:可可西里 更新时间:2023-11-01 03:11:29 24 4
gpt4 key购买 nike

我有一个应用程序可以播放录制的音频以及重复的声音。声音通过板载 iPad 扬声器正确播放,如果我从耳机插孔插入一条线到我的立体声音频输入,它也播放得很好。当我将我的 iPad 与我的蓝牙立体声输入配对时,来 self 的其他应用程序(为 iPhone 编写,在我的 iPad 上运行)的所有声音工作正常,来 self 设备的所有其他声音也是如此。

问题是我为 iPad 编写的应用程序没有通过蓝牙路径播放,而是通过内置扬声器播放。

在我的 didFinishLaunchingWithOptions(…) 方法中的应用委托(delegate)中,我放置了以下内容:

NSError *error = nil;
[[AVAudioSession sharedInstance] setMode:AVAudioSessionModeDefault error:&error];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
[[AVAudioSession sharedInstance] setActive:YES error:&error];

正在调用此代码并且未返回任何错误。

在我的 Controller 代码中,我记录了使用 AVAudioPlayer 播放的示例,如下所示:

audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:recordURL error:&error];
audioPlayer.numberOfLoops = 0;
[audioPlayer setDelegate:self];
[audioPlayer play];

在其他地区,我有无人机在线程控制循环中重复播放短的 .01 秒声音,我使用 OpenAL 执行此操作:

    alSourcePlay(sourceID);

这与我在为 iPhone 编写的其他应用程序中使用的代码相同,可以按预期工作。

我知道还有其他关于蓝牙输入的话题,但我的 iPad 应用程序的音频声音的蓝牙输出有一个具体问题。

最佳答案

因为您的类别是播放和录制,您必须启用蓝牙作为输入才能支持它作为输出(默认情况下,同一接收器用于播放和录制模式的输入/输出)。为此,您必须在 AVAudioSession 上设置一个额外的属性:

UInt32 allowBluetoothInput = 1;
AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
sizeof (allowBluetoothInput),
&allowBluetoothInput
);

您还需要通过在 session 中设置 kAudioSessionProperty_OverrideCategoryDe​​faultToSpeaker 属性来检查您是否没有在代码中的任何位置强制输出到内置扬声器。

关于ios - AVAudioPlayer 和 AVAudioSession 不会在 iPad(2 或其他)上播放蓝牙立体声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21314290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com