[英]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.