简体   繁体   English

无法为AVAudioSession设置类别

[英]Not able to set category for AVAudioSession

Trying to record audio with AVAudioSession . 尝试使用AVAudioSession录制音频。 But not able to set category end up with ambiguous without context error. 但是不能设置类别最终会导致模棱两可而没有上下文错误。

I'm using swift 4. 我正在使用Swift 4。

@objc func setupRecorder() {
    recordingSession = AVAudioSession.sharedInstance()

    do {
        try recordingSession?.setCategory(.playAndRecord, mode: .default)
        try recordingSession.setActive(true)
        recordingSession.requestRecordPermission() { [unowned self] allowed in
            DispatchQueue.main.async {
                if allowed {
                    self.startRecording()
                } else {
                    // failed to record!
                }
            }
        }
    } catch {
        // failed to record!
    }
}

在此处输入图片说明

If you are using "Swift4", then the method to set category is different, ie, 如果使用“ Swift4”,则设置类别的方法不同,即

AVAudioSession.sharedInstance().setCategory(String, mode: String, options: AVAudioSessionCategoryOptions)

ad you can use this via following way: 广告,您可以通过以下方式使用它:

try? AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeDefault, options: AVAudioSessionPortBuiltInSpeaker)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为 WKWebview 设置 AVAudioSession 类别 - Set AVAudioSession Category for WKWebview 如何给AVAudioSession中的两个类别设置类别 - how to give the two categories in AVAudioSession set category AVAudioSession类别无法按文档要求运行 - AVAudioSession category not working as documentation dictates AVAudioSession 将类别设置为没有选项的播放无法在 AirPods 上播放,同样设置类别没有选项将不会应用媒体信息 - AVAudioSession set category to playback without options fail to Play on AirPods, also set category without options will not apply media info AVAudioSession更改类别冻结AVCapture屏幕 - AVAudioSession Changing Category Freezing AVCapture Screen 是否可以订阅AVAudioSession类别/模式更改的事件? - Is it possible to subscribe to AVAudioSession Category/Mode changed events? AVAudioSession 类别变为 nil 并且 mediaServicesWereReset,avplayer 播放一直失败 - AVAudioSession category becomes nil and mediaServicesWereReset, avplayer playback keeps failing AVAudioSession的PlayAndRecord类和AVAudioSessionModeMeasurement与defaultToSpeaker选项不兼容? - AVAudioSession's PlayAndRecord category and AVAudioSessionModeMeasurement are incompatible with defaultToSpeaker option? 设置AVAudioSession类别对WKWebView的声音没有影响 - Setting AVAudioSession Category has no effect on sound from WKWebView 将AVAudioPlayer设置为AVAudioSession的输入数据源 - Set AVAudioPlayer as input data source for AVAudioSession
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM