我尝试使用AVAudioSession使用蓝牙设备播放语音。这是我在appdelegate.swift' s 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,扬声器,(蓝牙)
答案 0 :(得分:1)
你是对的,设置选项AllowBluetooth是在你的应用程序中打开蓝牙的唯一方法。但是蓝牙可能存在一些问题:
也许问题在于此。