[英]iOS 7 Can't have audio via bluetooth receiver using AVAudioSession
在iOS 7上我的應用程序使用藍牙時遇到了一個問題。更確切地說,我想連接的藍牙接收器是: http : //www.amazon.co.uk/Sony-Bluetooth-Receiver-增強智能手機-黑色/ 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];
有人對這個問題有什么想法嗎? 我錯過了什么嗎?
謝謝你的幫助!
您應該將類別設置為AVAudioSessionCategoryPlayback
。 當您將其設置為AVAudioSessionCategoryPlayAndRecord
,藍牙設備需要可用於輸入和輸出。 如果不是,則設備將默認使用內置揚聲器進行播放。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.