首页 文章

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

提问于
浏览
3

我想要连接到: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 回答

  • 1

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

相关问题