- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在开发音乐应用程序,它只播放来自应用程序的歌曲。现在我正在连接蓝牙扬声器播放。所以我正在设置 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")
}
}
我在 AppDelegate
的 didFinishLaunchingWithOptions
中调用这个函数。
但是如果我将 setCategory
更改为 audioSession.setCategory(AVAudioSessionCategoryPlayback)
它工作正常。
有人知道这段代码有什么问题吗?
谢谢
最佳答案
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/
我正在编写一个使用AVAudioSession记录用户音频的应用程序。当我不向选项中添加蓝牙时,所有功能都运行良好,但我也希望能够使用AirPods进行录制。当我添加.allowBluetooth选项
如果我通过启用某些选项(通过使用 setCategory:withOptions:error: )来设置 AVAudioSession 类别,然后调用 setCategory:error: ,那么之前
试试这个: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error]; if
我有一个视频捕捉应用程序,我希望能够在录制音频+视频的同时播放背景音乐。 如果我在 didFinishLaunchingWithOptions 中将 AVAudioSession 类别设置为 Play
我正在开发音乐应用程序,它只播放来自应用程序的歌曲。现在我正在连接蓝牙扬声器播放。所以我正在设置 AVAudioSession 类别,但它总是会返回错误。 代码: func setupSession
我想在手机处于静音模式时播放音频。 我可以在 >= iOS 10 中使用以下语句执行此操作: try AVAudioSession.sharedInstance().setCategory(AVAud
当我设置录制音频时,出现错误。 if (session.respondsToSelector("requestRecordPermission:")) { AVAudioSession.sha
我在一个只执行音频播放的应用程序中使用 AVAudioSession。我正在 applicationDidFinishLaunchingWithOptions: 中设置 audioSession 的模
try AVAudioSession.sharedInstance() .setCategory(AVAudioSessionCategoryPlayback,
迁移到 Swift 4.2 后,我收到多个错误,其中一个很奇怪。这似乎是 Xcode 10 中的错误,但是否有可用的解决方法? do { try AVAudioSession.sharedIn
问题的标题说明了一切。我有这个 fiddle SetCateforiesFiddleExample 我想要做的是将类别从月份更改为数字作为一个简单的示例,以应用于我的实际应用程序。有人可以帮助我解释为
我有一段代码以前可以在 Xcode 6 中运行,但现在不能在 Xcode 7 中运行。我在这里有一张它的图片 errors 我收到 3 个关于“无法分配值”、“无法调用initializer", "无
即使在静音模式下也能播放声音,我使用以下方法。但是它怎么不起作用。 // Works on Swift 3 do { try AVAudioSession.sharedInstance().
我是一名优秀的程序员,十分优秀!