Pra*_*ati 3 ios avaudiosession swift
我正在开发音乐应用程序,该应用程序仅播放应用程序中的歌曲。现在我正在连接蓝牙扬声器播放。所以我设置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")
}
}
Run Code Online (Sandbox Code Playgroud)
我在调用这个函数didFinishLaunchingWithOptions中AppDelegate。
但是,如果我更改setCategory为audioSession.setCategory(AVAudioSessionCategoryPlayback)正常工作。
有人知道这段代码有什么问题吗?
谢谢
仅当音频会话类别为playAndRecord或record时,才可以设置此选项。
与allowBluetooth您不能使用 AVAudioSessionCategoryPlayback
希望对您有所帮助
| 归档时间: |
|
| 查看次数: |
647 次 |
| 最近记录: |