首页 > 解决方案 > 用手机录制音频,但在 iOS 中通过蓝牙耳机播放录音

问题描述

是否可以用手机录制声音但通过蓝牙耳机强制播放?

这就是我设置 AVAudioSession 类别的方式

try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, with:[AVAudioSessionCategoryOptions.mixWithOthers])

录音被迫使用手机麦克风。但是,在播放声音时,它也会从手机中发出。我希望仅通过蓝牙耳机播放声音。

我尝试覆盖输出音频端口

try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSessionPortOverride.none)

但仍然没有工作。

标签: iosavaudioplayeravaudiosession

解决方案


问题已经解决了。我刚刚添加了 allowBluetoothA2DP 选项,然后它就可以工作了。

try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, with:[AVAudioSessionCategoryOptions.allowBluetoothA2DP, AVAudioSessionCategoryOptions.mixWithOthers])

推荐阅读