我'm trying to play the voice using a bluetooth device using AVAudioSession. Here is my code which I'已尝试放入appdelegate.swift的 didFinishLaunchingWithOptions
和viewcontroller.swift(一次一次)
import AVFoundation
var audioSession:AVAudioSession = AVAudioSession.sharedInstance()
audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.AllowBluetooth, error: nil)
所以代码执行完美但不使用连接的蓝牙设备 . 实际上,我在iPhone上打开控制中心,当应用程序未打开时,音频源显示为蓝牙设备,但是一旦应用程序打开,蓝牙设备选项就会消失...
其余代码(如果有任何用途)是 -
var engine = AVAudioEngine()
var input = engine.inputNode
var output = engine.outputNode
var format = input.inputFormatForBus(0)
var error:NSError?
var audioSession:AVAudioSession = AVAudioSession.sharedInstance() engine.startAndReturnError(&error)
它基本上是一个现场音频播放器,它从麦克风中取出声音并播放到AUX,扬声器,(蓝牙)
1 回答
你是对的,设置选项AllowBluetooth是在你的应用程序中打开蓝牙的唯一方法 . 但是蓝牙可能存在一些问题:
您的蓝牙设备不支持A2DP协议(高级音频分发配置文件),您可以通过标准音乐应用播放音乐来查看 .
如果您设置preferredBufferDuration或prefferedSampleRate,它也可能会影响蓝牙 .
也许问题在于此 .