【问题标题】:Playing using bluetooth in AVAudioSession在 AVAudioSession 中使用蓝牙播放
【发布时间】:2015-10-21 17:25:21
【问题描述】:

我正在尝试使用 AVAudioSession 使用蓝牙设备播放语音。这是我尝试在 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、扬声器、(蓝牙)

【问题讨论】:

    标签: ios swift avaudiosession avaudioengine


    【解决方案1】:

    您是对的,设置选项 AllowBluetooth 是在您的应用程序中打开蓝牙的一种也是唯一的方法。但是蓝牙可能会出现一些问题:

    1. 您的蓝牙设备不支持协议 A2DP(高级音频分发配置文件),您可以通过标准音乐应用播放音乐进行检查。
    2. 如果您设置preferredBufferDurationprefferedSampleRate 也可能会影响蓝牙。

    也许问题就出在这。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-03
      • 1970-01-01
      • 2014-07-16
      • 2012-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多