在 iOS 上使用 AVPlayer 连接蓝牙时音频失真

问题描述 投票:0回答:1

我一直在尝试在蓝牙扬声器上重现视频的音频,但由于音量非常低,音频会失真。视频使用 AVPlayer 再现,在 iOS 13 设备上播放时声音正确 根据我在研究过程中看到的一些评论,我添加了代码:

do {
    try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [.mixWithOthers, .allowBluetooth, .allowBluetoothA2DP,.defaultToSpeaker])
    try AVAudioSession.sharedInstance().setActive(true)
            
} catch(let error) {
    print("*** \(error) ***")
    Crashlytics.crashlytics().record(error: error)
} 

我在不同的地方尝试了前面的代码,在AVPlayer初始化之前、初始化之后或在AppDelegate中,都得到了相同的结果。

一些相关问题:

使用AVPlayer播放时如何将音频连接至蓝牙

iOS Swift - 使用蓝牙外部扬声器时音质较差

AVAudioSession setCategory Swift 4.2 iOS 12 - 在静音状态下播放声音

ios swift audio bluetooth avplayer
1个回答
0
投票

您想要删除

.allowBluetooth 
类别并使用
.allowBluetoothA2DP
代替。你不应该两者兼得。

allowBluetooth
类别使用HFP(免提配置文件)协议,该协议质量较低,通常用于打电话。

另一方面,

allowBluetoothA2DP
类别是仅输出。旨在用于更高带宽的音频用例。请参阅Apple的文档:

A2DP 是一种立体声、仅输出配置文件,适用于更高带宽的音频用例,例如音乐播放。

来源:

https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions/1771735-allowbluetootha2dp

https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions/1616518-allowbluetooth

© www.soinside.com 2019 - 2024. All rights reserved.