gpt4 book ai didi

iOS Swift - 使用蓝牙外置扬声器时音质不佳

转载 作者:行者123 更新时间:2023-11-28 08:30:32 26 4
gpt4 key购买 nike

我正在使用从 url 流式传输的 iOS 应用程序( radio 应用程序),一旦我尝试通过蓝牙设备(如外部扬声器或汽车音响系统)从应用程序流式传输,音频质量非常差且刺耳。从 iOS 设备本身播放时,一切听起来都不错(扬声器和耳机)。

    override func viewDidLoad() {
super.viewDidLoad()


// Set AVFoundation category, required for background audio
var error: NSError?
var success: Bool


do {

try AVAudioSession.sharedInstance().setCategory(
AVAudioSessionCategoryPlayAndRecord,

withOptions: [
AVAudioSessionCategoryOptions.AllowBluetooth,
AVAudioSessionCategoryOptions.DefaultToSpeaker])
success = true
} catch let error1 as NSError {
error = error1
success = false
}

if !success {
print("Failed to set audio session category. Error: \(error)")
}

最佳答案

感谢 Michal Cichon 的评论,这段代码终于对我有用,蓝牙也没有失真

        do{
if #available(iOS 10.0, *) {
try AVAudioSession.sharedInstance().setCategory(.playAndRecord,
mode: .default, options: [.mixWithOthers, .allowAirPlay,
.allowBluetoothA2DP,.defaultToSpeaker])
print("ios 10 and above")

} else {
print("ios 10 and lower")
let options: [AVAudioSession.CategoryOptions] =
[.mixWithOthers, .allowBluetooth]
let category = AVAudioSession.Category.playAndRecord
let selector =
NSSelectorFromString("setCategory:withOptions:error:")
AVAudioSession.sharedInstance().perform(selector, with:
category, with: options)
}

try AVAudioSession.sharedInstance().setActive(true)
captureSession.automaticallyConfiguresApplicationAudioSession =
false
}

关于iOS Swift - 使用蓝牙外置扬声器时音质不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38947490/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com