简体   繁体   English

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

[英]iOS 7 Can't have audio via bluetooth receiver using AVAudioSession

I'm facing an issue using bluetooth for my app on iOS 7. To be more precise, the bluetooth receiver i'd like to connect to is : http://www.amazon.co.uk/Sony-Bluetooth-Receiver-Enhancement-Smartphone-Black/dp/B00G9YK7LS 在iOS 7上我的应用程序使用蓝牙时遇到了一个问题。更确切地说,我想连接的蓝牙接收器是: http//www.amazon.co.uk/Sony-Bluetooth-Receiver-增强智能手机-黑色/ DP / B00G9YK7LS

Of course the iPhone is paired to the device before I start testing. 当然,在我开始测试之前,iPhone已经与设备配对。

My app should just make an audio pass through (from the mic to the speakers) using the EZAudio framework. 我的应用程序应该使用EZAudio框架将音频传递(从麦克风到扬声器)。 It works fine using the iPhone headset but not with the bluetooth. 使用iPhone耳机可以正常工作,但蓝牙无法使用。

Here's the code I put in the delegate class (didFinishLaunchingWithOptions function) to init the audio session : 这是我在委托类(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];

Then I use EZAudio framework to send audio to the audio device: 然后我使用EZAudio框架将音频发送到音频设备:

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

Anyone has any idea about this issue please? 有人对这个问题有什么想法吗? Have I missed something? 我错过了什么吗?

Thanks for your help! 谢谢你的帮助!

You should set the category to AVAudioSessionCategoryPlayback . 您应该将类​​别设置为AVAudioSessionCategoryPlayback When you have it set to AVAudioSessionCategoryPlayAndRecord , the bluetooth device needs to be available for input as well as output. 当您将其设置为AVAudioSessionCategoryPlayAndRecord ,蓝牙设备需要可用于输入和输出。 If it is not, the device will default to internal speakers for playback. 如果不是,则设备将默认使用内置扬声器进行播放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM