iOS 7使用AVAudioSession无法通过蓝牙接收器播放音频

时间:2014-08-12 08:12:03

标签: ios iphone audio ios7 bluetooth

我在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];

有人对此问题有任何疑问吗?我错过了什么吗?

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

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