【问题标题】:iOS 7 Can't have audio via bluetooth receiver using AVAudioSessioniOS 7 无法使用 AVAudioSession 通过蓝牙接收器获取音频
【发布时间】:2014-08-12 08:12:02
【问题描述】:

我在 iOS 7 上为我的应用程序使用蓝牙时遇到了问题。 更准确地说,我想连接的蓝牙接收器是:http://www.amazon.co.uk/Sony-Bluetooth-Receiver-Enhancement-Smartphone-Black/dp/B00G9YK7LS

当然,在我开始测试之前,iPhone 已与设备配对。

我的应用应该只使用 EZAudio 框架进行音频传递(从麦克风到扬声器)。使用 iPhone 耳机可以正常工作,但不能使用蓝牙。

这是我在委托类(didFinishLaunchingWithOptions 函数)中用于初始化音频会话的代码:

// configure the audio session
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = NULL;

// deactivate session
[audioSession setActive:NO error:&err];
if (err) {
    NSLog(@"There was an error deactivating the audio session");
}

[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&err];
if( err ){
    NSLog(@"There was an error creating the audio session");
}

[audioSession overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&err];
if( err ){
    NSLog(@"There was an error sending the audio to the speakers");
}

// Activate the session
[audioSession setActive:YES error:&err];

然后我使用 EZAudio 框架将音频发送到音频设备:

/**
 Start the output
 */
[EZOutput sharedOutput].outputDataSource = self;
[[EZOutput sharedOutput] startPlayback];

请问有人知道这个问题吗?我错过了什么吗?

感谢您的帮助!

【问题讨论】:

  • 没有想法?没有人面临同样的问题?

标签: ios iphone audio ios7 bluetooth


【解决方案1】:

您应该将类​​别设置为AVAudioSessionCategoryPlayback。当您将其设置为AVAudioSessionCategoryPlayAndRecord 时,蓝牙设备需要可用于输入和输出。如果不是,设备将默认使用内置扬声器进行播放。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-11
    • 2020-12-13
    • 2018-03-20
    • 2021-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多