gpt4 book ai didi

ios - AVAudioSession setCategory 总是返回错误

转载 作者:搜寻专家 更新时间:2023-10-31 22:04:17 27 4
gpt4 key购买 nike

我正在开发音乐应用程序,它只播放来自应用程序的歌曲。现在我正在连接蓝牙扬声器播放。所以我正在设置 AVAudioSession 类别,但它总是会返回错误。

代码:

 func setupSessionForPlaying() {
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayback, with: [.allowBluetooth])
try audioSession.setActive(true)
} catch {
fatalError("Error Setting Up Audio Session")
}
}

我在 AppDelegatedidFinishLaunchingWithOptions 中调用这个函数。

但是如果我将 setCategory 更改为 audioSession.setCategory(AVAudioSessionCategoryPlayback) 它工作正常。

有人知道这段代码有什么问题吗?

谢谢

最佳答案

根据文档 https://developer.apple.com/documentation/avfoundation/avaudiosession/categoryoptions/1616518-allowbluetooth

You can set this option only if the audio session category is playAndRecord or record.

allowBluetooth 不能使用 AVAudioSessionCategoryPlayback

希望对你有帮助

关于ios - AVAudioSession setCategory 总是返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52566011/

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