连接airpods时,扬声器不可用

时间:2019-03-22 14:42:58

标签: objective-c swift audio speaker

我正在尝试在用户按下按钮时将应用程序的音频覆盖到扬声器,但在连接airpods时扬声器没有显示为可用的音频输出。我该怎么做才能使声音传到扬声器?连接任何其他蓝牙设备时,此代码均有效。

po AVAudioSession.sharedInstance()。availableInputs

  

AVAudioSessionPortDescription:0x283dc3410,类型= MicrophoneBuiltIn;名称= iPhone麦克风; UID =内置麦克风; selectedDataSource =(空)>     VAudioSessionPortDescription:0x283dc32b0,类型= BluetoothHFP;名称= Lindsey的AirPods; UID = 94:B0:1F:C3:FF:6B-tsco; selectedDataSource =(空)>

var err: Error? = nil
let session = AVAudioSession.sharedInstance()
do {
    try session.setCategory(AVAudioSession.Category.playAndRecord, mode: .voiceChat, options: [.allowBluetooth, .allowBluetoothA2DP, .mixWithOthers])

} catch {
    NSLog("Unable to change audio category because : \(String(describing: err?.localizedDescription))")
    err = nil
}

do {
    try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
} catch let error as NSError {
    print("audioSession error turning on speaker: \(error.localizedDescription)")
}

0 个答案:

没有答案